Count Pairs
50% Success2423 Attempts20 Points1s Time Limit256MB Memory1024 KB Max Code

Problem:

You are given a sequence of integers \(A\) of length \(N\). Find the number of pairs of indices \((i,j)\) \((1\leq i \lt j \leq N)\) for which \(min(A[i],A[j]) \leq A[i] \oplus A[j]\).

Here, \(\oplus\) denotes the bitwise XOR operation.

Input Format:

  • The first line of the input contains a single integer \(T\) - the number of test cases. The description of \(T\) test cases follows.
  • The first line of each test case contains a single integer \(N\).
  • The second line contains \(N\) space-separated integers \(A_1, A_2, \ldots, A_N\)​.

Output Format:

  • For each test case print a single integer — the answer to the problem.

Constraints:

  • \(1 \leq T \leq 200\)
  • \(2 \leq N \leq 10^{5}\)
  • \(0 \leq A_i \lt 2^{30}\) for each valid \(i\)
  • The sum of \(N\) over all test cases does not exceed \(10^6\)
Examples
Input
2
2
1 2
3
4 5 9
Output
1
2
Explanation
  • Test case \(1\): The required pair of indices are \((1, 2)\).
  • Test case \(2\): The required pair of indices are \((1, 3)\) and \((2, 3)\).

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

Loading Editor...
Results