#P3149. 排序
排序
Description
There are people standing in front of Xiao A in order. Xiao A will perform operations on these people, one after another.
In each operation, choose a position . Take out from the line all people whose heights are less than or equal to the height of the person currently at position . Then, sort these extracted people by height in increasing order (from shortest to tallest), and put them back into the line at the same set of positions they originally occupied, filling those positions from left to right.
Xiao A is interested in the number of inversions of the sequence formed by these heights. Now Xiao A wants to know the inversion count of this sequence after each operation.
Update (2021-01-17): In the sequence, an inversion is a pair such that and .
Input Format
The first line contains two integers and , the number of people and the number of operations.
The next line contains integers , representing the heights from left to right in the initial state.
Each of the next lines contains one integer, the for that operation.
Output Format
Output lines. The first line is the number of inversions before any operation.
For , line is the inversion count after the -th operation.
5 2
1 5 3 4 2
3
4
5
4
3
Hint
[Sample Explanation #1] After the first operation, the sequence is . After the second operation, the sequence is .
Constraints For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号