luogu#P4887. 【模板】莫队二次离线 / 第十四分块(前体)

    ID: 3796 远端评测题 1000ms 40~500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>递推莫队O2优化前缀和洛谷月赛

【模板】莫队二次离线 / 第十四分块(前体)

Problem Description

Ctholly gives you a sequence aa. In each query, you are given an interval [l,r][l, r]. You need to count the number of pairs (i,j)(i, j) such that li<jrl \le i < j \le r, and the binary representation of aiaja_i \oplus a_j contains exactly kk ones. Here, \oplus means bitwise XOR.

Input Format

The first line contains three integers nn, mm, and kk.

The second line contains nn integers representing the sequence aa.

Then follow mm lines. Each line contains two integers ll and rr, representing one query.

Output Format

Output mm lines, each containing one integer, which is the answer to the corresponding query.

5 5 2
3 4 8 0 2
4 5
3 5
1 4
2 5
1 5
0
1
2
3
4

Hint

For 5%5\% of the testdata, it is the sample.

For 30%30\% of the testdata, 1n,m50001 \le n, m \le 5000.

For 50%50\% of the testdata, the memory limit is 512 MiB.

For 100%100\% of the testdata, it is guaranteed that 1n,m1051 \le n, m \le 10^5, and 0ai,k<2140 \le a_i, k < 2^{14}.

Translated by ChatGPT 5