CF1148C.Crazy Diamond

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a permutation pp of integers from 11 to nn , where nn is an even number.

Your goal is to sort the permutation. To do so, you can perform zero or more operations of the following type:

  • take two indices ii and jj such that 2ijn2 \cdot |i - j| \geq n and swap pip_i and pjp_j .

There is no need to minimize the number of operations, however you should use no more than 5n5 \cdot n operations. One can show that it is always possible to do that.

输入格式

The first line contains a single integer nn ( 2n31052 \leq n \leq 3 \cdot 10^5 , nn is even) — the length of the permutation.

The second line contains nn distinct integers p1,p2,,pnp_1, p_2, \ldots, p_n ( 1pin1 \le p_i \le n ) — the given permutation.

输出格式

On the first line print mm ( 0m5n0 \le m \le 5 \cdot n ) — the number of swaps to perform.

Each of the following mm lines should contain integers ai,bia_i, b_i ( 1ai,bin1 \le a_i, b_i \le n , aibin2|a_i - b_i| \ge \frac{n}{2} ) — the indices that should be swapped in the corresponding swap.

Note that there is no need to minimize the number of operations. We can show that an answer always exists.

输入输出样例

  • 输入#1

    2
    2 1
    

    输出#1

    1
    1 2
  • 输入#2

    4
    3 4 1 2
    

    输出#2

    4
    1 4
    1 4
    1 3
    2 4
    
  • 输入#3

    6
    2 5 3 1 4 6
    

    输出#3

    3
    1 5
    2 5
    1 4
    

说明/提示

In the first example, when one swap elements on positions 11 and 22 , the array becomes sorted.

In the second example, pay attention that there is no need to minimize number of swaps.

In the third example, after swapping elements on positions 11 and 55 the array becomes: [4,5,3,1,2,6][4, 5, 3, 1, 2, 6] . After swapping elements on positions 22 and 55 the array becomes [4,2,3,1,5,6][4, 2, 3, 1, 5, 6] and finally after swapping elements on positions 11 and 44 the array becomes sorted: [1,2,3,4,5,6][1, 2, 3, 4, 5, 6] .

首页