2582. When I sort…

单点时限: 2.0 sec

内存限制: 256 MB

In datastruct class, the teacher gives partychen a simple sort question:

A permutation , , …, is a sequence containing each number from to exactly once. The result of applying permutation to an array of length is an array of length , where (0-based indices).

Given an array , find a permutation which has the effect of sorting the elements of in non-descending order, i.e., an order where each element is greater than or equal to the previous one. If there are several suitable permutations output the lexicographically smallest one.

The permutation , , …, is considered lexicographically smaller than the permutation , , …, if there is an index such that and the equation holds for all .


The first line of input gives the number of cases, (). test cases follow.

In each test case, there are two lines. The first line is a interger (), representing the numbers of array , and in the second line there are intergers.


Output the permutation as discrible above.


2 3 1
2 1 3 1
1 2 0
2 0 3 1


In case 1: The element that is originally at position goes to position . The elements originally at positions and go to positions and , respectively.
In case 2: There are two suitable permutations: and . The first one is lexicographically smaller.

183 人解决,220 人已尝试。

255 份提交通过,共有 478 份提交。

6.4 EMB 奖励。

创建: 9 年,10 月前.

修改: 6 月前.

最后提交: 1 天,5 小时前.

来源: partychen