#P1997. faebdc 的烦恼

faebdc 的烦恼

Description

There are nn problems in this contest, each with a difficulty value aia_i. Since the ace coder wangxz has already sorted these difficulty values in ascending order for Niaoge, he does not want to know which problems are easy or hard; he only wants to know, among some problems al,al+1,,ara_l,a_{l+1},\ldots,a_r, how many times the most frequent difficulty value appears.

Your task is: for each query (l,r)(l, r), tell him, among the (rl+1)(r-l+1) problems from ala_l to ara_r, the number of occurrences of the most frequent difficulty value (there are qq queries in total).

If you succeed in helping Niaoge, he will take you through the NOI Qualifier.

Input Format

Each test point contains exactly one set of testdata.

The first line contains two integers, the number of problems nn and the number of queries qq.

The second line has nn integers; the ii-th integer aia_i is the difficulty of the ii-th problem.

Then follow qq lines, each with two integers l,rl, r, representing one query.

Output Format

For each query, output a single integer on its own line as the answer.

9 1
1 1 1 2 2 3 3 4 4
3 8
2

Hint

Constraints

对于全部的测试点,保证 1n1051 \leq n \leq 10^51q2×1051 \leq q \leq 2\times 10^5105ai105-10^5 \leq a_i \leq 10^51lrn1 \leq l \leq r \leq n

Translated by ChatGPT 5