#P7125. [Ynoi2008] rsmemq
[Ynoi2008] rsmemq
Problem Description
Given a sequence of length , define to be the mode of the interval if and only if there does not exist such that the number of occurrences of in the interval is greater than the number of occurrences of in the interval .
There are queries. Each query gives . For each query, find how many ordered pairs satisfy , and the length of interval is odd, and (note that this is an index, not the value at that index) is the mode of the interval .
Input Format
The first line contains two integers and .
The next line contains integers describing the sequence.
The following lines each contain two integers and , representing one query.
Output Format
Output lines in total, each being the answer for the corresponding query.
10 10
2 2 2 1 2 7 7 9 6 10
1 4
4 4
1 3
2 6
6 6
7 10
2 6
4 10
3 5
3 7
2
0
2
1
0
3
1
6
0
1
Hint
Idea: yummy&nzhtl1477, Solution: nzhtl1477, Code: nzhtl1477&czr, Data: nzhtl1477(partially uploaded)
For of the testdata: , , . All values are integers.
Sample explanation:
In , the subintervals that satisfy the conditions are , .
In , the subintervals that satisfy the conditions are , .
In , the subintervals that satisfy the conditions are .
In , the subintervals that satisfy the conditions are , , .
In , the subintervals that satisfy the conditions are , , , , , .
In , the subintervals that satisfy the conditions are .
Translated by ChatGPT 5