Description
Give you a array A[1..N] A[1..N], you need to calculate how many tuples (i,j,k) (i,j,k) satisfy that (i<j<k) (I and ((A[i] XOR A[j]) < (A[j] XOR a[k)) ((a[i]\ xor\ a[j])
There are T test cases.
1≤t≤20 1≤t≤20
1≤∑n≤5x105 1≤\sum n≤5x10^5
0≤a[i]<230 0≤a[i]
Input
There is only one integer T on the
For the all test case, the consists of one integer n, and the second line consists of n integers which means the Array A[1..N] A[1..N]
Output
For each test case, output an integer, which means the answer.
Sample Input
1
5
1 2 3 4 5
Sample Output
6
the
Given a sequence, look for the number of combinations (i,j,k) (i,j,k) that satisfy i<j<k I and ((A[i] XOR A[j]) < (A[J) XOR A[k]) (a[i]\ xor\. a[j)).
train of Thought
have been thinking about how to deal with these binary numbers, after looking at the puzzle found that the original can be inserted into the dictionary tree (should have thought of)
Traversing this sequence in the past, the dictionary tree is used to maintain the number of k−1 k-1, and the number of K K is currently processed.
For each number, because it is no larger than 230 2^{30}, we can use a CNT array to record the number of occurrences of each digit (1 or 0).
Node.next is the successor of a node in the dictionary tree, node.cnt the number of times the current node is accessed.
For k K and I i the highest difference bit KP k_p with IP i_p: when KP