#P7906. [Ynoi2005] rpxleqxq

[Ynoi2005] rpxleqxq

Problem Description

You are given a sequence aa of length nn consisting of positive integers, and a constant xx.

Let xyx \oplus y denote the bitwise XOR of xx and yy.

There are qq queries. Each query gives an interval [l,r][l, r]. You need to find how many pairs (i,j)(i, j) in this interval satisfy i<j(aiaj)xi < j \land (a_i \oplus a_j) \le x.

Input Format

The first line contains two positive integers n,xn, x, representing the length of the sequence and the given constant.

The next line contains nn integers representing the sequence aa.

The third line contains a positive integer qq, representing the number of queries.

The next qq lines each contain two positive integers l,rl, r, representing one query.

Output Format

Output qq lines. Each line contains one integer, representing the answer.

11 4
11 4 5 1 4 1 9 1 9 8 10
5
1 4
1 9
1 9
8 10
8 10
2
12
12
1
1

Hint

Idea: Dpair, Solution: Dpair, Code: Dpair, Data: Dpair & nzhtl1477.

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

For another 19%19\% of the testdata, n,q100n, q \le 100.

For another 19%19\% of the testdata, n,q1000n, q \le 1000.

For another 19%19\% of the testdata, q100q \le 100.

For another 19%19\% of the testdata, ai,x100a_i, x \le 100.

For 100%100\% of the testdata, 1n,ai,x2×1051 \le n, a_i, x \le 2 \times 10^5, and 1q1061 \le q \le 10^6.

Translated by ChatGPT 5