F. Adjacent exclusive OR (XOR)——相邻的异或(XOR)

    传统题 1000ms 256MiB

Adjacent exclusive OR (XOR)——相邻的异或(XOR)

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Statement

The XOR operation is a very common operation in computers. For a binary number with only one digit, the XOR operation output is true (1) if and only if the two input values are different, otherwise the output is false (0), that is, ''the same is 0, different is 1".

For some numbers, we have a bitwise exclusive OR operator denoted as a(10)b(10)a_{(10)}\oplus b_{(10)}, which means converting a,ba,b into binary bits and performing an exclusive OR operation on each bit to get a new number. For example, 595\oplus9 is calculated as follows:

$$5_{(10)}\oplus9_{(10)}=0101_{(2)}\oplus1001_{(2)}=1100_{(2)}=12_{(10)} $$

so we can calculate 59=125\oplus9=12. In mainstream programming languages, the exclusive OR symbol is generally ^ . For example, in C++, typing int x = a ^ b; means xabx\leftarrow a\oplus b.

In this problem, you are given an array aa of length nn. For each index ii in the array that satisfies 0i<n10 \le i < n-1, you can perform the following operation at most once[1]:

  • The assignment is ai:=aiai+1a_i := a_i \oplus a_{i+1}, where \oplus represents the bitwise exclusive OR operation. It should be noted that aia_i represents the i+1i+1th number in the array aa, for example, a0=1a_0=1 in the array [1,2,3,4,5][1,2,3,4,5] instead of the ii base.

You can choose the indices and perform the operations in any order. Given another array bb of length nn, determine whether aa can be transformed into bb using the operations.

Input

The first line contains an integer nn (2n21052 \le n \le 2 \cdot 10^5).

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (0ai<2300 \le a_i < 2^{30}).

The third line contains nn integers b1,b2,,bnb_1, b_2, \dots, b_n (0bi<2300 \le b_i < 2^{30}).

Output

For each test case, if aa can be converted to bb, then output ''Yes'' (without quotes); otherwise, output "No''.

Samples

5
1 2 3 4 5
3 2 7 1 5
Yes
3
0 0 1
1 0 1
No
3
0 0 1
0 0 0
No
4
0 0 1 2
1 3 3 2
No
 6
 1 1 4 5 1 4
 0 5 4 5 5 4
Yes

Notes

In the first example, you can perform the following operations in the following order:

  1. Choose subscript i=2i=2 so that a2:=a2a3=7a_2 := a_2 \oplus a_3 = 7, and aa becomes [1,2,7,4,5][1, 2, 7, 4, 5];
  2. Choose subscript i=3i=3 so that a3:=a3a4=1a_3 := a_3 \oplus a_4 = 1, and aa becomes [1,2,7,1,5][1, 2, 7, 1, 5];
  3. Choose subscript i=0i=0 so that a0:=a0a1=3a_0 := a_0 \oplus a_1 = 3, and aa becomes [3,2,7,1,5][3, 2, 7, 1, 5].

From this we can see that aa can be transformed into bb.


  1. This refers to performing the operation once per index, not just once globally. For example, you can perform the operation at index i=0i=0 and then at index i=1i=1, but you cannot perform the operation at index i=0i=0 again. ↩︎

2025 JSUT Collegiate Programming Contest 江苏理工学院新生赛-同步赛

未参加
状态
已结束
规则
ACM/ICPC
题目
15
开始于
2025-11-8 12:00
结束于
2025-11-8 17:00
持续时间
5 小时
主持人
参赛人数
15