#P7128. 「RdOI R1」序列(sequence)
「RdOI R1」序列(sequence)
Description
There is a sequence of length , and each number in the sequence appears exactly once.
That is, the sequence is a permutation of to .
There is only one allowed operation on sequence : for a number , you may swap it with or (if they exist).
Now, please turn sequence into an increasing sequence, and output the operations you perform in order.
Input Format
The input has a total of lines.
Line contains positive integer .
Line contains positive integers, .
Output Format
The output has a total of lines, where is the number of operations you perform.
Lines to each contain two integers , , meaning to swap the positions of and .
3
3 1 2
1 3
1 2
7
1 3 2 7 6 4 5
2 4
1 2
1 3
3 7
2 5
1 2
1 3
3 6
1 2
2 5
1 3
1 2
2 4
1 2
1 3
1 2
Hint
[Sample Explanation]
Explanation of Sample #1:
Swap and , and the sequence becomes: .
Then swap and , and the sequence becomes: .
[Constraints]
For of the testdata, .
For of the testdata, , .
[Hint]
- Use Special Judge.
- .
- Perform at most operations.
- The sample output is just one of many possible solutions.
- Because it is
special judge, no additional samples are provided.
[File Input/Output] (Simulation, not needed when submitting code)
- File name:
sequence.cpp. - Input file name:
sequence.in. - Output file name:
sequence.out.
Translated by ChatGPT 5
京公网安备 11011102002149号