#P3149. 排序

排序

Description

There are nn people standing in front of Xiao A in order. Xiao A will perform mm operations on these nn people, one after another.

In each operation, choose a position kk. Take out from the line all people whose heights are less than or equal to the height of the person currently at position kk. 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 nn heights. Now Xiao A wants to know the inversion count of this sequence after each operation.


Update (2021-01-17): In the aa sequence, an inversion is a pair (i,j)(i, j) such that i<ji < j and ai>aja_i > a_j.

Input Format

The first line contains two integers nn and mm, the number of people and the number of operations.

The next line contains nn integers aia_i, representing the heights from left to right in the initial state.

Each of the next mm lines contains one integer, the kk for that operation.

Output Format

Output m+1m + 1 lines. The first line is the number of inversions before any operation.

For i2i \ge 2, line ii is the inversion count after the (i1)(i - 1)-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 1,5,2,4,31, 5, 2, 4, 3. After the second operation, the sequence is 1,5,2,3,41, 5, 2, 3, 4.

Constraints For 100%100 \% of the testdata, 1n,m3×1051 \le n,m \le 3 \times 10^5, 1kn1 \le k \le n, 1ai1091 \le a_i \le 10^9.

Translated by ChatGPT 5