#P14457. [ICPC 2025 Xi'an R] Killing Bits

[ICPC 2025 Xi'an R] Killing Bits

题目描述

You are given two arrays aa and bb, both consisting of nn non-negative integers. You can perform the following operation on the array aa an arbitrary number of times (possibly, zero):

  • First, you select a permutation pp of 0,1,,n10, 1, \ldots, n - 1;
  • Then, for each 1in1\le i\le n, you set aia_i to ai&pia_i\operatorname{\&} p_i. Here, &\& denotes the bitwise AND operation.

You have to determine whether it is possible to transform aa into bb.

输入格式

The input consists of multiple test cases. The first line contains an integer tt (1t1041 \leq t \leq 10^4), the number of test cases. For each test case:

  • The first line contains a single integer nn (1n51041\le n\le 5\cdot 10^4), which is the length of arrays aa and bb.
  • The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (0ain10\le a_i\le n - 1), which are the elements of aa.
  • The third line contains nn integers b1,b2,,bnb_1, b_2, \ldots, b_n (0bin10\le b_i\le n - 1), which are the elements of bb.

It is guaranteed that the sum of nn over all test cases does not exceed 51045\cdot 10^4.

输出格式

For each test case, print Yes\texttt{Yes} in a single line if it is possible to transform aa into bb. Otherwise, print No\texttt{No}.

You can output the answer in any case (upper or lower). For example, the strings yEs\texttt{yEs}, yes\texttt{yes}, Yes\texttt{Yes}, and YES\texttt{YES} will be recognized as positive responses.

4
3
0 1 2
2 1 0
5
1 0 1 3 4
0 0 1 1 4
8
1 2 3 4 5 6 7 7
1 2 3 4 5 6 7 7
8
7 7 7 7 7 7 7 7
1 2 3 4 5 6 7 7
No
Yes
Yes
No

提示

In the first test case, we need to use at least one operation to transform aa into bb. Note that a1&p1a_1 \operatorname{\&} p_1 is always 00 because a1=0a_1 = 0. However, b1>0b_1>0, so it is impossible to make a1=b1a_1 = b_1, no matter how the permutations are selected during the operations.

In the second test case, you can select p=[2,0,3,1,4]p = [2, 0, 3, 1, 4]. After this operation, aa is transformed into bb.

In the third test case, a=ba = b, so we do not need any operations.