#P15457. 【MX-X25-T1】『FeOI-5』序列变换
【MX-X25-T1】『FeOI-5』序列变换
Problem Description
Given a sequence of length , repeatedly perform the following operations:
- , let be the (the smallest non-negative integer that does not appear) of the set ;
- , update to .
Find how many different sequences will be generated during this process (including the original sequence, i.e., the sequence after round ). Two sequences of length are different if and only if such that .
Input Format
The first line contains two integers , representing the subtask index of the test points (the samples guarantee that ) and the number of test cases.
For each test case, the input consists of two lines:
- The first line contains one integer ;
- The second line contains integers describing the sequence .
Output Format
For each test case, output one line with one integer, representing the answer.
0 1
5
3 2 1 1 4
3
0 1
12
1 0 3 2 2 1 4 5 6 8 7 9
4
Hint
[Sample 1 Explanation]
These are the results after the first few rounds of operations:
3 2 1 1 4
0 0 0 0 0
1 1 1 1 1
0 0 0 0 0
It is easy to see that afterwards, the sequence will keep alternating between the all- sequence and the all- sequence. Therefore, a total of sequences will be generated, so the answer is .
[Sample 2 Explanation]
These are the results after the first few rounds of operations:
1 0 3 2 2 1 4 5 6 8 7 9
0 2 2 4 4 4 5 6 7 7 9 10
1 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1 1 1
[Constraints]
For all testdata, , , .
| Subtask Index | Special Property | Score | |
|---|---|---|---|
| None | |||
| None | |||
Translated by ChatGPT 5