CF1870B.Friendly Arrays
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given two arrays of integers — a1,…,an of length n, and b1,…,bm of length m. You can choose any element bj from array b (1≤j≤m), and for all 1≤i≤n perform ai=ai∣bj. You can perform any number of such operations.
After all the operations, the value of x=a1⊕a2⊕…⊕an will be calculated. Find the minimum and maximum values of x that could be obtained after performing any set of operations.
Above, ∣ is the bitwise OR operation, and ⊕ is the bitwise XOR operation.
给你两个整数数组:长度为 n 的数组 a1,…,an,以及长度为 m 的数组 b1,…,bm。你可以从数组 b 中任选一个元素 bj(其中 1≤j≤m),并对所有 1≤i≤n 执行操作 ai=ai∣bj。你可以执行任意多次此类操作。
在所有操作完成后,计算值 x=a1⊕a2⊕…⊕an。请找出在执行任意一系列操作后,x 可能取到的最小值和最大值。
输入格式
The first line contains a single integer t (1≤t≤104) — the number of test cases. This is followed by the description of the test cases.
The first line of each test case contains two integers n and m (1≤n,m≤2⋅105) — the sizes of arrays a and b.
The second line of each test case contains n integers a1,a2,…,an (0≤ai≤109) — the array a.
The third line of each test case contains m integers b1,b2,…,bm (0≤bi≤109) — the array b.
It is guaranteed that the sum of values of n and m across all test cases does not exceed 2⋅105.
第一行包含一个整数 t(1≤t≤104),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 m(1≤n,m≤2⋅105),分别表示数组 a 和 b 的大小。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(0≤ai≤109),即数组 a。
每个测试用例的第三行包含 m 个整数 b1,b2,…,bm(0≤bi≤109),即数组 b。
保证所有测试用例中 n 和 m 的总和不超过 2⋅105。
输出格式
For each test case, output 2 numbers: the minimum and maximum possible values of x after performing any set of operations.
对于每个测试用例,输出 2 个数:执行任意一组操作后 x 的最小可能值和最大可能值。
输入输出样例
输入#1
2 2 3 0 1 1 2 3 3 1 1 1 2 1
输出#1
0 1 2 3
说明/提示
In the first test case, if we apply the operation with element b1=1, the array a will become [1,1], and x will be 0. If no operations are applied, then x=1.
In the second test case, if no operations are applied, then x=2. If we apply the operation with b1=1, then a=[1,1,3], and x=3.
在第一个测试用例中,若对元素 b1=1 执行操作,则数组 a 将变为 [1,1],且 x=0。若不执行任何操作,则 x=1。
在第二个测试用例中,若不执行任何操作,则 x=2。若对 b1=1 执行操作,则 a=[1,1,3],且 x=3。
输入解题思路,AI测评打分。不知道怎么写?