Count pairs
40% Success2818 Attempts20 Points1s Time Limit256MB Memory1024 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\)
Examples
Input
1 3 5 4 2 4 6 3 5 6
Output
3
Explanation
Approach
- For pair (1,3):
- (2^6) & 5 = .(2^6) & 4 = 4
- For pair (2,3):
- (4^6) & 5 = .(5^6) & 4 = 4
- For pair (3,3)
- (6^6) & 5 = .(6^6) & 4 = 0
- Therefore, the required answer is 3.
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
Loading Editor...
Results