Hdu 6059 Kanade ' s Trio (dictionary tree) __ data structure

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.