#P8257. [CTS2022] 普罗霍洛夫卡

[CTS2022] 普罗霍洛夫卡

Problem Description

Given a sequence a1,…,ana_1,\dots,a_n and a total of mm queries, each query provides l,rl,r. You need to compute the bitwise XOR sum of the weights of all pairs (L,R)(L,R) that satisfy l≤L≤R≤rl\le L\le R\le r. The weight of a pair (L,R)(L,R) is ∣{ai∣L≤i≤R}∣|\{a_i\mid L\le i\le R\}|.

Input Format

Read from standard input.

The first line contains two integers n mn\ m.

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

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

Output Format

Write to standard output.

Output mm lines, in order, each being the answer to the corresponding query.

5 2
1 1 1 2 4
1 5
3 5

3
2

Hint

For 5%5\% of the testdata, 1≤n,m≤1001\le n,m\le 100.

For 10%10\% of the testdata, 1≤n,m≤50001\le n,m\le 5000.

For 20%20\% of the testdata, 1≤n,m≤1051\le n,m\le 10^5.

For 30%30\% of the testdata, 1≤n,m≤2×1051\le n,m\le 2\times 10^5.

For 40%40\% of the testdata, 1≤n,m≤3×1051\le n,m\le 3\times 10^5.

For 50%50\% of the testdata, 1≤n,m≤3.5×1051\le n,m\le 3.5\times 10^5.

For another 10%10\% of the testdata, m=n2m=n^2.

For another 10%10\% of the testdata, for all i=1⋯ni=1\cdots n, ai≤2a_i\le 2.

For another 10%10\% of the testdata, for all i=1⋯ni=1\cdots n, ai≤10a_i\le 10.

For 100%100\% of the testdata, 1≤n,m≤4×1051\le n,m\le 4\times 10^5, 1≤ai≤n1\le a_i\le n, and all values are integers.

Each category of testdata forms a subtask.

Translated by ChatGPT 5