#P10149. [Ynoi1999] XM66F
[Ynoi1999] XM66F
Background

Problem Description
Given a sequence and queries. Each query gives . For each query, find how many triples satisfy and .
Input Format
The first line contains two integers .
The second line contains integers .
The next lines each contain two integers , representing a query.
Output Format
Output lines. Each line contains one integer, the answer to each query in order.
10 5
9 8 5 4 5 1 5 1 5 8
2 8
4 9
7 9
6 7
2 3
4
4
1
0
0
Hint
Idea: ccz181078, Solution: ccz181078, Code: ccz181078, Data: ccz181078.
All values are integers.
For of the testdata, , , and .
Translated by ChatGPT 5