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\)
Submissions
Please login to view your submissions
Similar Problems
Points:20
47 votes
Tags:
ApprovedEasyMathOpen
Points:20
15 votes
Tags:
SortingBasic ProgrammingBit ManipulationMerge SortBasics of Bit ManipulationAlgorithmsBit manipulationBitmask
Points:20
71 votes
Tags:
Basic ProgrammingBit ManipulationBit manipulationMath
Editorial