Dynamic Inversion#2050

Dynamic Inversion

1 segundo
122,174 megabytes
Muy fácil (≈850)

You are given a permutation {, , , ..., }. Remove elements one by one, and output the number of inversion pairs before each removal. The number of inversion pairs in an array is the number of ordered pairs (, ) such that < and A_i > A_j.

Entrada

Consists of several tests. The first line of each test contains two integers and (1 \le n \le 2 \cdot 10^5, 1 \le m \le 10^5). Next, lines follow, specifying the initial permutation. The following lines contain the numbers to be removed, in the order they are removed. No number is removed twice.

Salida

For each removal, output the number of inversion pairs before it.

Ejemplos

(, , , , ) -> (, , , ) -> (, , ) -> (, ) -> ()

Ejemplo 1

Loading
Loading