You are given an array \(A\) containing \(N\) integers and \(Q\) queries. Each query is denoted by two integers \(L, R\). The answer to a query is \(A_L + (A_L \oplus A_{L+1}) + \dots + (A_L \oplus A_{L+1} \oplus \dots \oplus A_R)\), where \(\oplus\) denotes the bitwise XOR operator.
Input format
- The first line contains two integers \(N\) denoting the size of array A and \(Q\) denoting the number of queries:
- The second line contains \(N\) space-separated integers \(A_1, A_2, \dots, A_N\) - denoting the elements of A.
- Each of the next \(Q\) lines contains two integers \(L, R.\)
Output format
For each test query, print the answer in a separate line.
Constraints
The answer to the first query is \( = A_3 + (A_3 \oplus A_4) = 2 + (2 \oplus 6) = 2 + 4 = 6.\)
The answer to the second query is \( = A_1 + (A_1 \oplus A_2) + (A_1 \oplus A_2 \oplus A_3) = 1 + (1 \oplus 7) + (1 \oplus 7 \oplus 2) = 1 + 6 + 4 = 11.\)
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor