luogu#P11365. [Ynoi2024] 新本格魔法少女りすか
[Ynoi2024] 新本格魔法少女りすか
Background


Problem Description
Given a permutation , there are queries. In the -th query, you are given intervals , satisfying . You need to find how many pairs satisfy , and there exist such that .
Input Format
The first line contains two integers .
The next line contains integers .
Then, for each query, the first line contains , followed by lines each containing .
Output Format
Output lines. The -th line should be the answer to the -th query.
5 2
5 4 2 3 1
3
1 1
2 3
4 4
2
1 2
3 4
1
0
Hint
Idea: nzhtl1477, Solution: ccz181078, Code: ccz181078, Data: ccz181078.
Constraints: For of the testdata, , , , , and all values are integers.
For of the testdata, .
For another of the testdata, .
For another of the testdata, .
For the remaining of the testdata, there are no special constraints.
Translated by ChatGPT 5