#P2709. 【模板】莫队 / 小B的询问

【模板】莫队 / 小B的询问

Description

Xiao B has an integer sequence aa of length nn, with values in [1,k][1, k]. He has mm queries. For each query, given an interval [l,r][l, r], compute:

i=1kci2\sum\limits_{i=1}^k c_i^2

where cic_i denotes the number of occurrences of the number ii in [l,r][l, r].

Please help Xiao B answer the queries.

Input Format

The first line contains three integers n,m,kn, m, k.

The second line contains nn integers, representing Xiao B's sequence.

Each of the next mm lines contains two integers l,rl, r.

Output Format

Output mm lines. Each line contains one integer, which is the answer to a query.

6 4 3
1 3 2 1 1 3
1 4
2 6
3 5
5 6
6
9
5
2

Hint

Constraints
For 100%100\% of the testdata, 1n,m,k5×1041 \le n, m, k \le 5 \times 10^4.

Translated by ChatGPT 5