#P15352. [COCI 2025/2026 #4] 魔术 / Magija
[COCI 2025/2026 #4] 魔术 / Magija
Background
Please note that this problem has an unusual memory limit.
Problem Description
Consider a permutation of . Define an operation as follows:
- For , swap and .
It is guaranteed that and do not overlap.
There is an operation pool, initially empty.
There are events:
- : Starting from the permutation , perform any number of operations from the operation pool (possibly zero times), and find the minimum and maximum possible final index of after all operations are done.
- An operation can be used multiple times.
- The order of operations does not matter.
- You do not have to use all operations in the pool.
- : Add an operation to the operation pool.
Answer each query.
Input Format
The first line contains two positive integers ().
The next lines each contain two (or four) positive integers, in the form or , describing an event. Where:
- ;
- , , .
Output Format
For each event , output one line with two positive integers, representing the minimum and maximum possible final index, respectively.
5 3
2 3 4 1
1 5
1 3
5 5
3 4
9 2
2 1 7 2
1 2
2 8
Hint
Sample Explanation
Explanation for sample 2: doing no operations gives the minimum value; performing the operation once gives the maximum value.
Subtasks
| Subtask ID | Score | Constraints |
|---|---|---|
| No additional constraints. |
Translated by ChatGPT 5