Count pairs
Practice
3.8 (11 votes)
Bit manipulation
Basic programming
Basics of bit manipulation
C++
Problem
40% Success 2817 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given the following:
- An integer \(N\)
- An integer \(X\)
- An integer \(Y\)
- An array \(A\) of \(N\) elements
- An array \(B\) of \(N\) elements
Find the number of pairs of \((i, j)\) such that:
- \((A[i] \text{^}B[j])\&X = (A[i] \text{^}B[j])\&Y\), where ^ represents bitwise XOR operator and & represents bitwise AND operator.
- \(1 \le i, j \le N\)
Note: Assume \(1\)-based indexing.
Input
- The first line contains a single integer \(T\) that denotes the number of test cases.
- For each test case:
- The first line contains an integer \(N\).
- The second line contains an integer \(X\).
- The third line contains an integer \(Y\).
- The next line contains \(N\) space-separated integers denoting array \(A\).
- The next line contains \(N\) space-separated integers denoting array \(B\).
Output format
For each test case, print the number of pairs \((i, j)\) that satisfy the conditions in a new line.
Constraints
\(1 \le T \le 10 \\ 1 \le N \le 10^5 \\ 1 \le X, Y \le 10^6 \\ 0 \le A[i], B[i] \le 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:20
71 votes
Tags:
Basic ProgrammingBit ManipulationBit manipulationMath
Points:20
22 votes
Tags:
Basic ProgrammingBit ManipulationBit manipulationEasy
Points:20
11 votes
Tags:
BitmaskBasics of Bit ManipulationBasic ProgrammingBit ManipulationBit manipulationBasics of bit manipulation
Editorial
Login to unlock the editorial