CF2254F.Whiplash
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Yousef has given you an even integer n and two arrays, a and b, both consisting of n non-negative integers.
You can perform the following operation on array a any number of times (possibly zero):
- Choose an index i (1≤i≤n).
- For all j such that 1≤j≤n and j=i, replace aj with aj⊕ai. (Here, ⊕ denotes the bitwise XOR operation).
- The element ai remains unchanged.
Determine whether it is possible to transform array a into array b using a finite number of operations.
优素福给了你一个偶数 n 和两个数组 a 与 b,它们均包含 n 个非负整数。
你可以对数组 a 执行以下操作任意多次(包括零次):
- 选择一个下标 i(1≤i≤n);
- 对所有满足 1≤j≤n 且 j=i 的 j,将 aj 替换为 aj⊕ai(此处 ⊕ 表示按位异或运算);
- 元素 ai 保持不变。
判断是否可以通过有限次操作将数组 a 变为数组 b。
输入格式
The first line contains an integer t (1≤t≤104) — the number of test cases. The description of the test cases follows.
The first line of each test case contains an even integer n (2≤n≤2⋅105) — the length of the array.
The second line of each test case contains n integers a1,a2,…,an (0≤ai<230) — the elements of the array a.
The third line of each test case contains n integers b1,b2,…,bn (0≤bi<230) — the elements of the array b.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
第一行包含一个整数 t(1≤t≤104)——测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含一个偶数 n(2≤n≤2⋅105)——数组的长度。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(0≤ai<230)——数组 a 的元素。
每个测试用例的第三行包含 n 个整数 b1,b2,…,bn(0≤bi<230)——数组 b 的元素。
保证所有测试用例中 n 的总和不超过 2⋅105。
输出格式
For each test case, output "YES" if the array a can be transformed into array b 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.
对于每个测试用例,如果数组 a 可以通过有限次操作转换为数组 b,则输出 "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], there is no sequence of operations that ends at [1,0], so the answer is "NO".
In the second test case, one valid sequence is:
- Choose index 2, [1,2,4,7]→[3,2,6,5].
- Choose index 3, [3,2,6,5]→[5,4,6,3].
- Choose index 4, [5,4,6,3]→[6,7,5,3].
In the third test case, one valid sequence is:
- Choose index 1, [1,2,4,8]→[1,3,5,9].
- Choose index 2, [1,3,5,9]→[2,3,6,10].
- Choose index 3, [2,3,6,10]→[4,5,6,12].
- Choose index 2, [4,5,6,12]→[1,5,3,9].
- Choose index 4, [1,5,3,9]→[8,12,10,9].
- Choose index 1, [8,12,10,9]→[8,4,2,1].
在第一个测试用例中,从 [1,2] 出发,不存在任何操作序列能到达 [1,0],因此答案为 "NO"。
在第二个测试用例中,一个合法的操作序列如下:
- 选择下标 2,[1,2,4,7]→[3,2,6,5]。
- 选择下标 3,[3,2,6,5]→[5,4,6,3]。
- 选择下标 4,[5,4,6,3]→[6,7,5,3]。
在第三个测试用例中,一个合法的操作序列如下:
- 选择下标 1,[1,2,4,8]→[1,3,5,9]。
- 选择下标 2,[1,3,5,9]→[2,3,6,10]。
- 选择下标 3,[2,3,6,10]→[4,5,6,12]。
- 选择下标 2,[4,5,6,12]→[1,5,3,9]。
- 选择下标 4,[1,5,3,9]→[8,12,10,9]。
- 选择下标 1,[8,12,10,9]→[8,4,2,1]。
输入解题思路,AI测评打分。不知道怎么写?