410092: GYM103940 I Inversion Counting

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

I. Inversion Countingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

You have a sequence of $$$N$$$ integers $$$a_i$$$ with elements between $$$1$$$ and $$$K$$$, and you want to calculate the number of inversions. To make it more complicated you get $$$Q$$$ operations $$$i$$$, change all occurrences of $$$i$$$ to $$$i+1$$$, and vice versa.

Each operation changes the original sequence for the following operations.

note: is considered an inversion to a pair of indices ($$$i, j$$$), where $$$i < j$$$ and $$$a_i > a_j$$$.

Input

The first line contains three integers $$$N$$$, $$$K$$$, $$$Q$$$ ($$$1\le K\le N\le 100\,000$$$, $$$1\le Q\le 1\,000\,000$$$).

The next line contains $$$N$$$ integers $$$a_1, a_2, \dots, a_N$$$ ($$$1 \le a_i \le K$$$) specifying the sequence.

The following $$$Q$$$ lines each contain an integer $$$i$$$ ($$$1\le i \le K-1$$$), representing the operation of swapping $$$i$$$ elements with $$$i+1$$$, and vice versa.

Output

For each $$$Q$$$ operation, print a single integer, the number of inversions as specified in the statement.

ExampleInput
5 4 3
1 4 2 1 2
3
2
1
Output
4
2
2

加入题单

算法标签: