Bob And The Magic Pairs
Practice
3.3 (3 votes)
Trie
Advanced data structures
Data structures
Problem
63% Success 416 Attempts 50 Points 1s Time Limit 256MB Memory 1024 KB Max Code
Bob is a brilliant student in the class, so his teacher assigned him a problem. He has been given an array \(A\) containing \(N\) positive integers and two integers \(U\) and \(V\). He has been asked to find the number of magic pairs of array indices.
A pair of integers \((i, j)\) is called a magic pair if \(i < j\) and \(U ≤ A[i] \text{^} A[j] ≤ V\) where \(\text{^}\) denotes the bitwise XOR operation.
Help Bob to find the number of magic pairs in the given array.
Input Format:
- The first line contains a single integer \(T\) denoting the number of test cases.
- The first line of each test case contains the integers \(N\), \(U\), and \(V\) separated by spaces.
- The second line of each test case contains \(N\) spaced integers, the elements of the array \(A\).
Output Format:
For each test case, print the number of magic pairs in the given array.
Constraints:
\(1 \leq T \leq 10 \\ 1 \leq N \leq 10^4 \\ 0 \leq A[i] \leq 10^9 \\ 0 \leq U \leq V \leq 10^9\)
Submissions
Please login to view your submissions
Similar Problems
Points:50
12 votes
Tags:
Advanced Data StructuresData StructuresDepth First SearchLCASegment TreesTries
Points:50
3 votes
Tags:
TrieAdvanced Data StructuresC++Data Structures
Points:50
6 votes
Tags:
Data StructuresAdvanced Data StructuresTrie
Editorial