Count Pairs
Practice
3.6 (9 votes)
Basic programming
Bit manipulation
Basics of bit manipulation
Problem
50% Success 2403 Attempts 20 Points 1s Time Limit 256MB Memory 1024 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\)
Submissions
Please login to view your submissions
Similar Problems
Points:20
9 votes
Tags:
Basic ProgrammingBit ManipulationBit manipulationEasyImplementation
Points:20
56 votes
Tags:
ApprovedBasic ProgrammingBit manipulationEasyOpen
Points:20
10 votes
Tags:
ApprovedBasic ProgrammingBit manipulationEasyGrammar-VerifiedImplementationPriority queueReadyRecruit
Editorial