#P7601. [THUPC 2021] 区间本质不同逆序对
[THUPC 2021] 区间本质不同逆序对
Description
You are given a sequence of length .
There are queries. Each query gives an interval . For each query, compute $|\{(a_i, a_j) : l \le i < j \le r \wedge a_i > a_j\}|$.>
, .
Input Format
The first line contains a positive integer .
The second line contains positive integers. The -th number is the value at position in the sequence. It is guaranteed that .
The third line contains a positive integer .
Then follow lines. Each line contains two positive integers separated by two spaces, denoted , representing one query. It is guaranteed that .
Output Format
Output lines. The -th line contains one integer, which is the answer to the -th query.
5
2 1 3 2 1
4
2 4
1 5
3 5
2 2
1
3
3
0
Hint
[Sample Explanation]
For the first query, the set is .
For the second and third queries, the set is .
For the fourth query, the set is the empty set.
[Source]
From the 2021 Tsinghua University Student Programming Contest and Intercollegiate Invitational (THUPC2021).
Resources such as editorial solutions can be found at https://github.com/yylidiw/thupc_0/tree/master.
Translated by ChatGPT 5
京公网安备 11011102002149号