#P7882. [Ynoi2006] rsrams

[Ynoi2006] rsrams

Problem Description

Given a sequence a1,,ana_1,\dots,a_n of length nn, you need to process mm queries. Each query gives l,rl, r, and the answer is:

$\sum\limits_{L=l}^r \sum\limits_{R=L}^r \sum\limits_{c=1}^n c\cdot \left[R-L+1<2\sum\limits_{i=L}^R [a_i=c] \right]$.

Here [cond][\mathrm{cond}] means that if the condition expression inside the brackets is true, then [cond]=1[\mathrm{cond}]=1; otherwise, [cond]=0[\mathrm{cond}]=0.

Input Format

The first line contains two integers n,mn, m.

The second line contains nn integers a1,,ana_1,\dots,a_n.

The next mm lines each contain two integers l,rl, r, representing a query.

Output Format

Output mm lines. Each line contains one integer, representing the answer to each query.

3 2
1 1 2
1 3
2 3
6
3

Hint

Idea: zjjcth330, Solution: nzhtl1477&ccz181078, Code: ccz181078, Data: ccz181078.

Constraints: For 100%100\% of the testdata, 1n1061\le n\le 10^6, 1m1061\le m\le 10^6, 1ain1\le a_i\le n, 1lrn1\le l\le r\le n.

Translated by ChatGPT 5