report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
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 ```
Square root decomposition
Frequency
Tree query
Inversions query
Nearest vertex
Dominating color
String occurences 3
Inversions query 2
Pair
Sparse update
Tree
Range query
String concatenation
Subarray distance
Chameleon
Knapsack
Bit counting
Subsequence queries
Sub-subsequence
Delete numbers
Mode
Marisa is happy
Inversions query 3
Upperbound
23 path
Yet another square root decomposition problem
Marisa plays poker
Wonderful world
Topic
Data structure
Rating 1700
Solution (1) Solution