CF1870B.Friendly Arrays

普及/提高-

通过率:0%

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 ( 1jm1 \leq j \leq m ), and for all 1in1 \leq i \leq n perform ai=aibja_i = a_i | b_j . You can perform any number of such operations.

After all the operations, the value of x=a1a2anx = 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.

输入格式

The first line contains a single integer tt ( 1t1041 \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 ( 1n,m21051 \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 ( 0ai1090 \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 ( 0bi1090 \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 21052 \cdot 10^5 .

输出格式

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

输入输出样例

  • 输入#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 .

首页