CF2254F.Whiplash

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Yousef has given you an even integer nn and two arrays, aa and bb, both consisting of nn non-negative integers.

You can perform the following operation on array aa any number of times (possibly zero):

  • Choose an index ii (1≤i≤n1 \le i \le n).
  • For all jj such that 1≤j≤n1 \le j \le n and j≠ij \neq i, replace aja_j with aj⊕aia_j \oplus a_i. (Here, ⊕\oplus denotes the bitwise XOR operation).
  • The element aia_i remains unchanged.

Determine whether it is possible to transform array aa into array bb using a finite number of operations.

优素福给了你一个偶数 nn 和两个数组 aa 与 bb,它们均包含 nn 个非负整数。

你可以对数组 aa 执行以下操作任意多次(包括零次):

  • 选择一个下标 ii(1≤i≤n1 \le i \le n);
  • 对所有满足 1≤j≤n1 \le j \le n 且 j≠ij \neq i 的 jj,将 aja_j 替换为 aj⊕aia_j \oplus a_i(此处 ⊕\oplus 表示按位异或运算);
  • 元素 aia_i 保持不变。

判断是否可以通过有限次操作将数组 aa 变为数组 bb。

输入格式

The first line contains an integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases. The description of the test cases follows.

The first line of each test case contains an even integer nn (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5) — the length of the array.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (0≤ai<2300 \le a_i \lt 2^{30}) — the elements of the array aa.

The third line of each test case contains nn integers b1,b2,…,bnb_1, b_2, \dots, b_n (0≤bi<2300 \le b_i \lt 2^{30}) — the elements of the array bb.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)——测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个偶数 nn(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5)——数组的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(0≤ai<2300 \le a_i \lt 2^{30})——数组 aa 的元素。

每个测试用例的第三行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \dots, b_n(0≤bi<2300 \le b_i \lt 2^{30})——数组 bb 的元素。

保证所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output "YES" if the array aa can be transformed into array bb using a finite number of operations, and "NO" otherwise.

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.

对于每个测试用例,如果数组 aa 可以通过有限次操作转换为数组 bb,则输出 "YES";否则输出 "NO"。

你可以以任意大小写形式输出答案(大写或小写均可)。例如,字符串 "yEs"、"yes"、"Yes" 和 "YES" 均会被识别为肯定回答。

输入输出样例

  • 输入#1

    6
    2
    1 2
    1 0
    4
    1 2 4 7
    6 7 5 3
    4
    1 2 4 8
    8 4 2 1
    4
    1 2 3 4
    1 2 4 5
    4
    1 2 0 3
    3 3 0 3
    6
    3 5 6 9 10 12
    6 5 3 12 15 9

    输出#1

    NO
    YES
    YES
    NO
    NO
    YES

说明/提示

In the first test case, starting from [1,2][1, 2], there is no sequence of operations that ends at [1,0][1, 0], so the answer is "NO".

In the second test case, one valid sequence is:

  • Choose index 22, [1,2,4,7]→[3,2,6,5][1, {\color{blue}{2}}, 4, 7] \rightarrow [3, {\color{blue}{2}}, 6, 5].
  • Choose index 33, [3,2,6,5]→[5,4,6,3][3, 2, {\color{blue}{6}}, 5] \rightarrow [5, 4, {\color{blue}{6}}, 3].
  • Choose index 44, [5,4,6,3]→[6,7,5,3][5, 4, 6, {\color{blue}{3}}] \rightarrow [6, 7, 5, {\color{blue}{3}}].

In the third test case, one valid sequence is:

  • Choose index 11, [1,2,4,8]→[1,3,5,9][\color{blue}{1}, 2, 4, 8] \rightarrow [\color{blue}{1}, 3, 5, 9].
  • Choose index 22, [1,3,5,9]→[2,3,6,10][1, \color{blue}{3}, 5, 9] \rightarrow [2, \color{blue}{3}, 6, 10].
  • Choose index 33, [2,3,6,10]→[4,5,6,12][2, 3, \color{blue}{6}, 10] \rightarrow [4, 5, \color{blue}{6}, 12].
  • Choose index 22, [4,5,6,12]→[1,5,3,9][4, \color{blue}{5}, 6, 12] \rightarrow [1, \color{blue}{5}, 3, 9].
  • Choose index 44, [1,5,3,9]→[8,12,10,9][1, 5, 3, \color{blue}{9}] \rightarrow [8, 12, 10, \color{blue}{9}].
  • Choose index 11, [8,12,10,9]→[8,4,2,1][\color{blue}{8}, 12, 10, 9] \rightarrow [\color{blue}{8}, 4, 2, 1].

在第一个测试用例中,从 [1,2][1, 2] 出发,不存在任何操作序列能到达 [1,0][1, 0],因此答案为 "NO"。

在第二个测试用例中,一个合法的操作序列如下:

  • 选择下标 22,[1,2,4,7]→[3,2,6,5][1, {\color{blue}{2}}, 4, 7] \rightarrow [3, {\color{blue}{2}}, 6, 5]。
  • 选择下标 33,[3,2,6,5]→[5,4,6,3][3, 2, {\color{blue}{6}}, 5] \rightarrow [5, 4, {\color{blue}{6}}, 3]。
  • 选择下标 44,[5,4,6,3]→[6,7,5,3][5, 4, 6, {\color{blue}{3}}] \rightarrow [6, 7, 5, {\color{blue}{3}}]。

在第三个测试用例中,一个合法的操作序列如下:

  • 选择下标 11,[1,2,4,8]→[1,3,5,9][\color{blue}{1}, 2, 4, 8] \rightarrow [\color{blue}{1}, 3, 5, 9]。
  • 选择下标 22,[1,3,5,9]→[2,3,6,10][1, \color{blue}{3}, 5, 9] \rightarrow [2, \color{blue}{3}, 6, 10]。
  • 选择下标 33,[2,3,6,10]→[4,5,6,12][2, 3, \color{blue}{6}, 10] \rightarrow [4, 5, \color{blue}{6}, 12]。
  • 选择下标 22,[4,5,6,12]→[1,5,3,9][4, \color{blue}{5}, 6, 12] \rightarrow [1, \color{blue}{5}, 3, 9]。
  • 选择下标 44,[1,5,3,9]→[8,12,10,9][1, 5, 3, \color{blue}{9}] \rightarrow [8, 12, 10, \color{blue}{9}]。
  • 选择下标 11,[8,12,10,9]→[8,4,2,1][\color{blue}{8}, 12, 10, 9] \rightarrow [\color{blue}{8}, 4, 2, 1]。

输入解题思路,AI测评打分。不知道怎么写?

首页