P14457 [ICPC 2025 Xi'an R] Killing Bits

Description

You are given two arrays $a$ and $b$, both consisting of $n$ non-negative integers. You can perform the following operation on the array $a$ an arbitrary number of times (possibly, zero): - First, you select a permutation $p$ of $0, 1, \ldots, n - 1$; - Then, for each $1\le i\le n$, you set $a_i$ to $a_i\operatorname{\&} p_i$. Here, $\&$ denotes the bitwise AND operation. You have to determine whether it is possible to transform $a$ into $b$.

Input Format

The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$), the number of test cases. For each test case: - The first line contains a single integer $n$ ($1\le n\le 5\cdot 10^4$), which is the length of arrays $a$ and $b$. - The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0\le a_i\le n - 1$), which are the elements of $a$. - The third line contains $n$ integers $b_1, b_2, \ldots, b_n$ ($0\le b_i\le n - 1$), which are the elements of $b$. It is guaranteed that the sum of $n$ over all test cases does not exceed $5\cdot 10^4$.

Output Format

For each test case, print $\texttt{Yes}$ in a single line if it is possible to transform $a$ into $b$. Otherwise, print $\texttt{No}$. You can output the answer in any case (upper or lower). For example, the strings $\texttt{yEs}$, $\texttt{yes}$, $\texttt{Yes}$, and $\texttt{YES}$ will be recognized as positive responses.

Explanation/Hint

In the first test case, we need to use at least one operation to transform $a$ into $b$. Note that $a_1 \operatorname{\&} p_1$ is always $0$ because $a_1 = 0$. However, $b_1>0$, so it is impossible to make $a_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]$. After this operation, $a$ is transformed into $b$. In the third test case, $a = b$, so we do not need any operations.