#P12263. 『STA - R9』回听
『STA - R9』回听
Problem Description
Given a sequence of length , define the playback operation as follows:
Define one playback operation as: choose any , and then perform the following operation any number of times (possibly times):
- , choose a , swap , and set .
Let be the minimum possible value of after performing one playback operation.
Note that the playback operation does not actually affect the values of the sequence . You may assume that after the operation, returns to the state before the operation.
The sequence will undergo modification operations. Each time, given , increase every number from to by . After each modification, you need to output how many essentially different there are after performing one playback operation (two values and are essentially different if and only if ).
Note: modification operations affect each other, while playback operations are independent of each other.
Input Format
The first line contains two integers .
The second line contains integers, where the -th integer represents .
The next lines each contain integers, representing .
Output Format
Output lines. Each line contains one integer, representing the number of essentially different .
3 1
2 2 2
2 3 1
2
4 3
6 5 6 6
3 3 1
1 3 2
4 4 5
3
4
2
Hint
[Operation Explanation]
For the sequence , the playback operation proceeds as follows:
If we choose and perform operations, with chosen being respectively, then the entire sequence changes as:
[Sample Explanation]
After the modification operation, the sequence becomes .
When , choose , perform operations, and choose as respectively, obtaining .
When , choose , perform operation, choose , obtaining .
When , choose , perform operation, choose , obtaining .
Therefore, the sequence is , so the answer is .
[Constraints]
This problem uses bundled testdata.
- Subtask 0 (10 pts): .
- Subtask 1 (15 pts): , , , .
- Subtask 2 (15 pts): .
- Subtask 3 (30 pts): .
- Subtask 4 (30 pts): no special constraints.
For all testdata, it is guaranteed that , , .
The input/output size of this problem is large. It is recommended to use fast IO methods.
Translated by ChatGPT 5