#P17494. [ICPC 2026 Wuhan I] Sequence Operations
[ICPC 2026 Wuhan I] Sequence Operations
Problem Description
Given a sequence of non-negative integers , and two sequences of length , and . It is guaranteed that all are positive integers.
You need to perform operations in order from to . In the -th operation, you modify the current sequence based on the value of :
- If , you must perform for all .
- If , you must perform for all .
- If , you can freely choose to perform either of the two operations mentioned above.
After all operations are completed, determine whether it is possible to make all elements in sequence equal.
Additional notes regarding the and operations are as follows:
- The binary operation is defined as the smallest non-negative integer that is not equal to and not equal to . For example: , .
- For the greatest common divisor , it is specifically defined that .
Input Format
The input contains multiple test cases. The first line contains an integer (), the number of test cases.
For each test case:
- The first line contains two integers (), representing the length of sequence and the number of operations.
- The second line contains non-negative integers (), representing the initial sequence.
- The next lines each contain two integers (, ), representing the type parameter and value parameter of the -th operation.
It is guaranteed that across all test cases, and .
Output Format
For each test case, output one line. If it is possible to make all numbers equal after all operations are finished, output “Yes”; otherwise, output “No”.
7
8 6
3 1 4 1 5 9 2 6
0 1
0 1
0 4
0 5
0 1
0 4
3 1
0 1 2
1 1
3 1
0 1 2
2 1
4 2
3 3 5 0
1 1
2 3
2 2
3 0
2 4
2 2
4 2
3 0 2 0
1 1
1 3
3 4
1 4 0
1 1
1 1
0 4
2 2
Yes
No
Yes
No
No
No
Yes
Hint
For the first test case: in the first operation, choose to apply the operation, and the sequence becomes . In the following operations, no matter which operation you choose, the elements of the sequence will always remain equal, so output “Yes”.
For the second test case: the only operation is , , so you can only choose the operation.
The final sequence becomes , and it is impossible to make all numbers equal, so output “No”.