CF1870B.Friendly Arrays

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given two arrays of integers — a1,…,ana_1, \ldots, a_n of length nn, and b1,…,bmb_1, \ldots, b_m of length mm. You can choose any element bjb_j from array bb (1≤j≤m1 \leq j \leq m), and for all 1≤i≤n1 \leq i \leq n perform ai=ai∣bja_i = a_i | b_j. You can perform any number of such operations.

After all the operations, the value of x=a1⊕a2⊕…⊕anx = a_1 \oplus a_2 \oplus \ldots \oplus a_n will be calculated. Find the minimum and maximum values of xx that could be obtained after performing any set of operations.

Above, ∣| is the bitwise OR operation, and ⊕\oplus is the bitwise XOR operation.

给你两个整数数组:长度为 nn 的数组 a1,…,ana_1, \ldots, a_n,以及长度为 mm 的数组 b1,…,bmb_1, \ldots, b_m。你可以从数组 bb 中任选一个元素 bjb_j(其中 1≤j≤m1 \leq j \leq m),并对所有 1≤i≤n1 \leq i \leq n 执行操作 ai=ai∣bja_i = a_i | b_j。你可以执行任意多次此类操作。

在所有操作完成后,计算值 x=a1⊕a2⊕…⊕anx = a_1 \oplus a_2 \oplus \ldots \oplus a_n。请找出在执行任意一系列操作后,xx 可能取到的最小值和最大值。

上式中,∣| 表示按位或运算,⊕\oplus 表示按位异或运算。

输入格式

The first line contains a single integer tt (1≤t≤1041 \leq t \leq 10^4) — 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 nn and mm (1≤n,m≤2⋅1051 \leq n, m \leq 2 \cdot 10^5) — the sizes of arrays aa and bb.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤1090 \leq a_i \leq 10^9) — the array aa.

The third line of each test case contains mm integers b1,b2,…,bmb_1, b_2, \ldots, b_m (0≤bi≤1090 \leq b_i \leq 10^9) — the array bb.

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

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

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n,m≤2⋅1051 \leq n, m \leq 2 \cdot 10^5),分别表示数组 aa 和 bb 的大小。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤1090 \leq a_i \leq 10^9),即数组 aa。

每个测试用例的第三行包含 mm 个整数 b1,b2,…,bmb_1, b_2, \ldots, b_m(0≤bi≤1090 \leq b_i \leq 10^9),即数组 bb。

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

输出格式

For each test case, output 22 numbers: the minimum and maximum possible values of xx after performing any set of operations.

对于每个测试用例,输出 22 个数:执行任意一组操作后 xx 的最小可能值和最大可能值。

输入输出样例

  • 输入#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=1b_1 = 1, the array aa will become [1,1][1, 1], and xx will be 00. If no operations are applied, then x=1x = 1.

In the second test case, if no operations are applied, then x=2x = 2. If we apply the operation with b1=1b_1 = 1, then a=[1,1,3]a = [1, 1, 3], and x=3x = 3.

在第一个测试用例中,若对元素 b1=1b_1 = 1 执行操作,则数组 aa 将变为 [1,1][1, 1],且 x=0x = 0。若不执行任何操作,则 x=1x = 1。

在第二个测试用例中,若不执行任何操作,则 x=2x = 2。若对 b1=1b_1 = 1 执行操作,则 a=[1,1,3]a = [1, 1, 3],且 x=3x = 3。

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

首页