#abc350c. C - Sort (WAITING SPJ)
C - Sort (WAITING SPJ)
Score: points
问题陈述
给定一个排列 ,它是 的一个排列。 通过执行以下操作0到N-1次(包括N-1次)将 转换为 :
- 操作:选择任意一对整数 ,使得 。交换 中第 个和第 个位置的元素。
可以证明,在给定的约束条件下,总是可以将 转换为 。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
You are given a permutation of .
Transform into by performing the following operation between and times, inclusive:
- Operation: Choose any pair of integers such that . Swap the elements at the -th and -th positions of .
It can be proved that under the given constraints, it is always possible to transform into .
Constraints
- is a permutation of .
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Let be the number of operations. Print lines.
The first line should contain .
The -th line () should contain the integers and chosen for the -th operation, separated by a space.
Any output that satisfies the conditions in the problem statement will be considered correct.
Sample Input 1
5
3 4 1 2 5
Sample Output 1
2
1 3
2 4
The operations change the sequence as follows:
- Initially, .
- The first operation swaps the first and third elements, making .
- The second operation swaps the second and fourth elements, making .
Other outputs such as the following are also considered correct:
4
2 3
3 4
1 2
2 3
Sample Input 2
4
1 2 3 4
Sample Output 2
0
Sample Input 3
3
3 1 2
Sample Output 3
2
1 2
2 3