report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
Inversions query - MarisaOJ: Marisa Online Judge

Inversions query

Time limit: 2000 ms
Memory limit: 256 MB
Given an permutation $P$ of $n$ integers and $q$ queries, each of the form $(l, r)$, count the number of inversions in the subarray $P[l...r]$. An inversion in an array $A$ is a pair of indices $i < j$ and $A_i > A_j$. ### Input - The first line contains 2 integers $n, q$. - The second line contains $n$ integers $P_i$ which form a permutation. - The next $q$ line, each line contains 2 integers $l, r$, a query. ### Output - Print the answer for each query. ### Constraints - $1 \le n,q \le 10^5$. ### Example Input: ``` 4 2 1 3 2 4 1 2 2 4 ``` Output: ``` 0 1 ```
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 1500
Source YS
Solution (0) Solution