Count Pairs
Practice
3.6 (9 votes)
Basic programming
Bit manipulation
Basics of bit manipulation
Problem
50% Success 2420 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\)
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
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
2 votes
Tags:
MathematicsHardOpenApproved
Points:20
22 votes
Tags:
Basic ProgrammingBit ManipulationBit manipulationEasy
Points:20
15 votes
Tags:
SortingBasic ProgrammingBit ManipulationMerge SortBasics of Bit ManipulationAlgorithmsBit manipulationBitmask
Editorial
Login to unlock the editorial