#P7999. [WFOI - 01] 翻转序列(requese)
[WFOI - 01] 翻转序列(requese)
Background
Why don’t you go solve this problem after finishing this one?
Problem Description
You need to sort a permutation of on a strange computer.
You may choose a number . Then each time, you may reverse a segment of length or a segment of length .
Please restore the sequence to within operations.
(Setter’s note: The current best can be under 15000 operations. Please try to optimize your algorithm.)
Input Format
The input consists of lines.
The first line contains an integer .
The second line contains integers, representing the sequence .
Output Format
The output consists of lines.
The first two lines each contain integer, which are respectively. Here, is the number of operations.
The next lines each contain two integers, representing the left and right endpoints of the reversed interval.
This problem uses , and you will be judged as long as the reverse operations are correct.
2
2 1
1
1
1 2
5
5 2 3 4 1
4
2
1 5
2 4
Hint
-
Sample explanation:
Reverse , and the sequence becomes .
-
Sample explanation:
Reverse , and the sequence becomes .
Reverse , and the sequence becomes .
This problem uses bundled Subtask tests.
| Subtask ID | Constraints and Notes |
|---|---|
| Subtask #0 () | |
| Subtask #1 () | |
| Subtask #2 () | |
| Subtask #3 () | |
| Subtask #4 () | |
| Subtask #5 () | |
| Subtask #6 () |
For of the testdata, , and the data guarantees that is a permutation of .
Translated by ChatGPT 5