#P6718. [CCO 2018] Flop Sorting
[CCO 2018] Flop Sorting
Description
Robert created a segment tree problem. The problem is:
Given a permutation of length , we define a flop operation as swapping the minimum value and the maximum value in an interval. Now you are given flop operations; each time you perform a flop operation on . Find the final sequence after performing the flop operations.
After finishing the statement, the next step is to prepare the testdata.
Now you are given , the initial sequence , and the final sequence. Find the flop operations to be performed in between.
Input Format
The first line contains an integer representing the length of the sequence .
The second line contains integers representing the initial sequence .
The third line contains integers representing the final sequence.
Output Format
First, output an integer , the number of flop operations to perform.
Then output lines, each with two integers , meaning to perform a flop operation on .
6
1 3 5 6 4 2
1 2 3 4 5 6
4
2 3
3 6
2 5
4 5
Hint
Sample Explanation
For sample , the flop operations performed are:
- Perform a flop operation on , swapping and .
- Perform a flop operation on , swapping and .
- Perform a flop operation on , swapping and .
- Perform a flop operation on , swapping and .
Constraints
For of the data, , , and .
For of the data, .
For another of the data, .
Notes
Translated from Canadian Computing Olympiad 2018 Day 2 C Flop Shorting。
Translated by ChatGPT 5
京公网安备 11011102002149号