Inversions query 2 - MarisaOJ: Marisa Online Judge

Inversions query 2

Time limit: 3000 ms
Memory limit: 512 MB
Given a permutation $P=\{1, 2,...,n\}$ and $q$ queries of the form $(x, y)$, swap elements with indices $x$ and $y$. Find the number of inversions in $P$ after each query. ### Input - The first line contains two integers $n, q$. - The next $q$ lines, each line contains two integers $x, y$, a query. ### Output - Print the answer for each query. ### Constraints - $1 \le n, q \le 10^5$. - $1 \le x,y \le n$. ### Example Input: ``` 5 4 4 5 2 4 2 5 2 2 ``` Output: ``` 1 4 3 3 ```