#P3149. Inversion Count after Reordering

    ID: 16407 Type: Default 1000ms 256MiB

Inversion Count after Reordering

Inversion Count after Reordering

There are \(n\) persons standing in a line in front of Little A. Little A will perform \(m\) operations on these persons. In each operation, a position \(k\) is chosen. Let the threshold be the height of the person at position \(k\) in the current sequence. Then, all persons whose heights are less than or equal to this threshold are taken out of the sequence. These removed persons are then reinserted back into their original positions in the order of increasing height (from left to right).

Little A is very interested in the number of inversion pairs in the sequence of heights. An inversion pair is defined as a pair \((i, j)\) such that \(i a_j\). After each operation, output the number of inversion pairs in the current sequence.

inputFormat

The first line contains two integers \(n\) and \(m\) separated by a space.

The second line contains \(n\) integers representing the heights of the persons.

The following \(m\) lines each contain one integer \(k\) (1-indexed), the position chosen for that operation.

outputFormat

For each operation, output a single line containing one integer: the number of inversion pairs in the sequence after the operation.

sample

5 1
3 1 4 2 5
3
0

</p>