#abc350c. C - Sort (WAITING SPJ)

C - Sort (WAITING SPJ)

Score: 300300 points

问题陈述

给定一个排列 A=(A1,,AN)A=(A_1,\ldots,A_N),它是 (1,2,,N)(1,2,\ldots,N) 的一个排列。 通过执行以下操作0到N-1次(包括N-1次)将 AA 转换为 (1,2,,N)(1,2,\ldots,N)

  • 操作:选择任意一对整数 (i,j)(i,j),使得 1i<jN1\leq i < j \leq N。交换 AA 中第 ii 个和第 jj 个位置的元素。

可以证明,在给定的约束条件下,总是可以将 AA 转换为 (1,2,,N)(1,2,\ldots,N)

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

You are given a permutation A=(A1,,AN)A=(A_1,\ldots,A_N) of (1,2,,N)(1,2,\ldots,N).
Transform AA into (1,2,,N)(1,2,\ldots,N) by performing the following operation between 00 and N1N-1 times, inclusive:

  • Operation: Choose any pair of integers (i,j)(i,j) such that 1i<jN1\leq i < j \leq N. Swap the elements at the ii-th and jj-th positions of AA.

It can be proved that under the given constraints, it is always possible to transform AA into (1,2,,N)(1,2,\ldots,N).

Constraints

  • 2N2×1052 \leq N \leq 2\times 10^5
  • (A1,,AN)(A_1,\ldots,A_N) is a permutation of (1,2,,N)(1,2,\ldots,N).
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN

A1A_1 \ldots ANA_N

Output

Let KK be the number of operations. Print K+1K+1 lines.
The first line should contain KK.
The (l+1)(l+1)-th line (1lK1\leq l \leq K) should contain the integers ii and jj chosen for the ll-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, A=(3,4,1,2,5)A=(3,4,1,2,5).
  • The first operation swaps the first and third elements, making A=(1,4,3,2,5)A=(1,4,3,2,5).
  • The second operation swaps the second and fourth elements, making A=(1,2,3,4,5)A=(1,2,3,4,5).

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