#P16316. [ICPC 2023 Jinan R] 奇怪的排序
[ICPC 2023 Jinan R] 奇怪的排序
Problem Description
:::epigraph[Stanley P. Y. Fung. Is this the simplest (and most surprising) sorting algorithm ever? arXiv:2110.01111] We present an extremely simple sorting algorithm. It looks obviously wrong, but we prove that it is actually correct. :::
After learning about the strange sorting algorithm in the problem "Paimon Sorting" from ICPC 2021 Asia Regional Nanjing Site, Xiaoqingyu came up with the following question.
Given a sequence , which is a permutation of size , you need to sort it in non-decreasing order. To do this, you may perform the following operation at most times: choose two indices and such that and , then sort in non-decreasing order.
Recall that a permutation of size is a sequence of length in which each integer from to (inclusive) appears exactly once. Also, denotes the greatest integer not larger than .
Input Format
There are multiple test cases. The first line contains an integer , the number of test cases. For each test case:
The first line contains an integer (), the length of the permutation.
The second line contains distinct integers (), representing the given permutation.
It is guaranteed that the sum of over all test cases does not exceed .
Output Format
For each test case, first output one line with an integer (), the number of operations you perform. Then output lines, where the -th line contains two integers and separated by a single space, indicating the two indices you choose for the -th operation.
It can be proven that an answer always exists. If there are multiple valid answers, you may output any one of them.
3
6
2 3 4 6 5 1
5
1 2 3 4 5
3
2 3 1
2
3 6
1 3
0
1
1 3
Hint
For the first sample, after the first operation the permutation becomes , and after the second operation it becomes . At this time, the permutation is in non-decreasing order.
Translated by ChatGPT 5