#P10370. 「LAOI-4」Mex Tower (Hard ver.)
「LAOI-4」Mex Tower (Hard ver.)
Background
The difference from the Easy Version is that this problem requires checking whether the solution is valid.
It is guaranteed that for all test points in this problem, the time and memory limits are at least times those of the standard solution (std).
Problem Description
Define as the smallest non-negative integer that does not appear in the set . For example, , and .
Next, we define one operation on a non-negative integer sequence as replacing sequence with a sequence of length , where .
Given an integer sequence of length , where , perform the operation times in order. Obviously, the final sequence will contain only one number. Define the value of this final number as the value of the sequence, denoted by .
For the given and sequence , determine whether for all non-negative integer sequences of length , it holds that .
Input Format
This problem contains multiple test cases.
The first line contains a positive integer , the number of test cases.
For each test case, the first line contains a positive integer .
The next line contains integers, representing the sequence .
Output Format
For each test case, output one string per line: Yes or No.
2
2
0 1
3
1 0 2
Yes
No
Hint
Sample Explanation
For , . It can be proven that for all sequences of length , .
For , . There exists a sequence with .
Constraints
"This problem uses bundled tests."
| Special Property | Total Score | ||
|---|---|---|---|
| None | |||
| None | |||
Special Property : It is guaranteed that .
Special Property : It is guaranteed that .
For all testdata, it is guaranteed that , , and .
Translated by ChatGPT 5