2131E.md (2010B)
1 Source: https://codeforces.com/problemset/problem/2131/E 2 3 E. Adjacent XOR 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're given an array $a$ of length $n$. For each index $i$ such that $1 \le i \lt n$, you can perform the following operation at most once: 22 23 * Assign $a_i := a_i \oplus a_{i+1}$, where $\oplus$ denotes the bitwise XOR operation. . 24 25 You can choose indices and perform the operations in any sequential order. 26 27 Given another array $b$ of length $n$, determine if it is possible to transform $a$ to $b$. 28 29 Input 30 31 Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows. 32 33 The first line of each test case contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$). 34 35 The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \lt 2^{30}$). 36 37 The third line of each test case contains $n$ integers $b_1, b_2, \dots, b_n$ ($0 \le b_i \lt 2^{30}$). 38 39 It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$. 40 41 Output 42 43 For each test case, output "YES" (quotes excluded) if $a$ can be transformed to $b$; otherwise, output "NO". You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses. 44 45 Example 46 47 Input 48 49 ``` 50 7 51 52 5 53 54 1 2 3 4 5 55 56 3 2 7 1 5 57 58 3 59 60 0 0 1 61 62 1 0 1 63 64 3 65 66 0 0 1 67 68 0 0 0 69 70 4 71 72 0 0 1 2 73 74 1 3 3 2 75 76 6 77 78 1 1 4 5 1 4 79 80 0 5 4 5 5 4 81 82 3 83 84 0 1 2 85 86 2 3 2 87 88 2 89 90 10 10 91 92 11 10 93 ``` 94 95 Output 96 97 ``` 98 YES 99 NO 100 NO 101 NO 102 YES 103 NO 104 NO 105 ``` 106 107 Note 108 109 In the first test case, you can perform the operations in the following order: 110 111 1. Choose index $i=3$ and assign $a_3 := a_3 \oplus a_4 = 7$, and $a$ becomes $[1, 2, 7, 4, 5]$. 112 2. Choose index $i=4$ and assign $a_4 := a_4 \oplus a_5 = 1$, and $a$ becomes $[1, 2, 7, 1, 5]$. 113 3. Choose index $i=1$ and assign $a_1 := a_1 \oplus a_2 = 3$, and $a$ becomes $[3, 2, 7, 1, 5]$.