Problem
You are given two binary arrays �A and �B, each of size �N (�≥3)(N≥3).
You can perform the following operation on array �A:
- Select three indexes �,�,i,j, and �k (1≤�<�<�≤�)(1≤i<j<k≤N),
and set ��=��Aj=Ai ∣∣ ��Aj ∣∣ ��Ak. Here ∣∣ denotes the bitwise OR operation.
Determine whether it is possible to convert the array �A to array �B by applying any (possibly zero) number of given operations.
Note that, in a binary array each element is either 00 or 11.
Input Format
- The first line of input will contain a single integer �T, denoting the number of test cases.
- Each test case consists of multiple lines of input:
- The first line of each test case contains a single integer �N — size of arrays.
- The second line of each test case contains �N space-separated integers �1,�2,�3,…,��A1,A2,A3,…,AN, the elements of array �A.
- The third line of each test case contains �N space-separated integers �1,�2,�3,…,��B1,B2,B3,…,BN, the elements of array �B.
Output Format
For each test case, output YES
, it is possible to convert the array �A to array �B using any number of given operations. Otherwise, output NO
.
You can output each character of the answer in uppercase or lowercase. For example, the strings yEs
, yes
, Yes
, and YES are considered the same.
Constraints
- 1≤�≤1051≤T≤105
- 3≤�≤1053≤N≤105
- ��Ai and ��Bi are either 00 or 11.
- The sum of �N over all test cases won’t exceed 5⋅1055⋅105.
Sample 1:
Input
Output
3 5 0 1 0 0 1 0 1 1 1 1 3 1 0 0 0 0 1 3 0 0 0 0 1 0
YES NO NO
Explanation:
Test case 11: We can perform the following operations to make the arrays equal:
- Operation 11: Select �=2,�=3,�=4i=2,j=3,k=4 and set �3=�2A3=A2 ∣∣ �3A3 ∣∣ �4A4 =1=1 ∣∣ 00 ∣∣ 0=10=1. Thus, the array becomes �=[0,1,1,0,1]A=[0,1,1,0,1].
- Operation 22: Select �=3,�=4,�=5i=3,j=4,k=5 and set �4=�3A4=A3 ∣∣ �4A4 ∣∣ �5A5 =1=1 ∣∣ 00 ∣∣ 1=11=1. Thus, the array becomes �=[0,1,1,1,1]A=[0,1,1,1,1].
The array �A is thus converted to array �B.
Test case 22: It is not possible to convert the array �A to array �B using any number of given operation.
Test case 33: It is not possible to convert the array �A to array �B using any number of given operation.
Accepted
3
Submissions
79
Accuracy
3.8