Problem 675
XOR Sum of All Pairs Bitwise AND
Hard · 30 pts · Math, Bit Manipulation
Problem
You are given two arrays A and B. For every pair (i, j), compute A[i] AND B[j], and then XOR all these N × M values together. Print the result. Computing every pair is too slow for 100000 × 100000 pairs. AND distributes over XOR just like multiplication over addition, so the answer equals (XOR of all of A) AND (XOR of all of B).
Input
The first line contains N and M. The second line contains A. The third line contains B.
Output
Print the XOR of all pairwise ANDs.
Constraints
1 <= N, M <= 100000; 0 <= A[i], B[j] <= 10^9
Example input
3 2 1 2 3 6 5
Example output
0
Explanation
With A = 1 2 3 and B = 6 5, the pairwise ANDs are 0, 1, 2, 0, 2 and 1. XOR-ing them all gives 0. The shortcut agrees: (1 XOR 2 XOR 3) AND (6 XOR 5) = 0 AND 3 = 0.