XOR Pairs

4.6

9 votes
Bit Manipulation, Basics of Bit Manipulation, Basic Programming
Problem

You are given an array A of N non-negative integers. Find the number of pairs of indices (i, j) (1i<jN), such that A[i]j=A[j]i, where is the bitwise XOR operator.

Input format

The first line contains a single integer T denoting the number of test cases.

For each test case, the first line contains a single integer N denoting the size of the array A. The next line contains N space-seperated integers denoting the elements of the array.

Output format

The output must contain a single integer, that is the number of pairs described in the statement.

Constraints

1T10

1N2×105

0A[i]109

It is guaranteed that the sum of N does not exceed 2×105 over all test cases.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In the first test case, it can be shown that no pairs satisfy the condition.

In the second test case, the pairs (1, 3) and (2, 4) satisfy the condition, as A[1]3=A[3]1=0 and A[2]4=A[4]2=0.

Editor Image

?