CF1375E.Inversion SwapSort
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Madeline has an array a of n integers. A pair (u,v) of integers forms an inversion in a if:
- 1≤u<v≤n .
- au>av .
Madeline recently found a magical paper, which allows her to write two indices u and v and swap the values au and av . Being bored, she decided to write a list of pairs (ui,vi) with the following conditions:
- all the pairs in the list are distinct and form an inversion in a .
- all the pairs that form an inversion in a are in the list.
- Starting from the given array, if you swap the values at indices u1 and v1 , then the values at indices u2 and v2 and so on, then after all pairs are processed, the array a will be sorted in non-decreasing order.
Construct such a list or determine that no such list exists. If there are multiple possible answers, you may find any of them.
输入格式
The first line of the input contains a single integer n ( 1≤n≤1000 ) — the length of the array.
Next line contains n integers a1,a2,...,an (1≤ai≤109) — elements of the array.
输出格式
Print -1 if no such list exists. Otherwise in the first line you should print a single integer m ( 0≤m≤2n(n−1) ) — number of pairs in the list.
The i -th of the following m lines should contain two integers ui,vi ( 1≤ui<vi≤n ).
If there are multiple possible answers, you may find any of them.
输入输出样例
输入#1
3 3 1 2
输出#1
2 1 3 1 2
输入#2
4 1 8 1 6
输出#2
2 2 4 2 3
输入#3
5 1 1 1 2 2
输出#3
0
说明/提示
In the first sample test case the array will change in this order [3,1,2]→[2,1,3]→[1,2,3] .
In the second sample test case it will be [1,8,1,6]→[1,6,1,8]→[1,1,6,8] .
In the third sample test case the array is already sorted.