1870B.md (2095B)
1 Source: https://codeforces.com/problemset/problem/1870/B 2 3 B. Friendly Arrays 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 You are given two arrays of integers — $a_1, \ldots, a_n$ of length $n$, and $b_1, \ldots, b_m$ of length $m$. You can choose any element $b_j$ from array $b$ ($1 \leq j \leq m$), and for all $1 \leq i \leq n$ perform $a_i = a_i | b_j$. You can perform any number of such operations. 22 23 After all the operations, the value of $x = a_1 \oplus a_2 \oplus \ldots \oplus a_n$ will be calculated. Find the minimum and maximum values of $x$ that could be obtained after performing any set of operations. 24 25 Above, $|$ is the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR), and $\oplus$ is the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). 26 27 Input 28 29 The first line contains a single integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases. This is followed by the description of the test cases. 30 31 The first line of each test case contains two integers $n$ and $m$ ($1 \leq n, m \leq 2 \cdot 10^5$) — the sizes of arrays $a$ and $b$. 32 33 The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_i \leq 10^9$) — the array $a$. 34 35 The third line of each test case contains $m$ integers $b_1, b_2, \ldots, b_m$ ($0 \leq b_i \leq 10^9$) — the array $b$. 36 37 It is guaranteed that the sum of values of $n$ and $m$ across all test cases does not exceed $2 \cdot 10^5$. 38 39 Output 40 41 For each test case, output $2$ numbers: the minimum and maximum possible values of $x$ after performing any set of operations. 42 43 Example 44 45 Input 46 47 ``` 48 2 49 50 2 3 51 52 0 1 53 54 1 2 3 55 56 3 1 57 58 1 1 2 59 60 1 61 ``` 62 63 Output 64 65 ``` 66 0 1 67 2 3 68 ``` 69 70 Note 71 72 In the first test case, if we apply the operation with element $b_1 = 1$, the array $a$ will become $[1, 1]$, and $x$ will be $0$. If no operations are applied, then $x = 1$. 73 74 In the second test case, if no operations are applied, then $x = 2$. If we apply the operation with $b_1 = 1$, then $a = [1, 1, 3]$, and $x = 3$.