Count Pairs

3.6

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

Problem:

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

Here,  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 A1,A2,,AN​.

Output Format:

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

Constraints:

  • 1T200
  • 2N105
  • 0Ai<230 for each valid i
  • The sum of N over all test cases does not exceed 106
Sample Input
2
2
1 2
3
4 5 9
Sample Output
1
2
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation
  • Test case 1: The required pair of indices are (1,2).
  • Test case 2The required pair of indices are (1,3) and (2,3).

 

Editor Image

?