#P8381. Sorting by Constrained Block Moves
Sorting by Constrained Block Moves
Sorting by Constrained Block Moves
You are given T test cases. For each test case you are given an integer n and a permutation a of the integers \(1,2,\dots,n\).
In the original problem, you are allowed to perform a special type of move. In each move you first choose an integer \(x\) and then you can select a contiguous block of the permutation whose length is either \(x+1\) or \(x-1\), and shift this block forward or backward by exactly \(x\) positions. The block that is passed over during this shift moves into the gap left by the moved block. The constraint is that you must sort the permutation into ascending order (i.e. \(1,2,\dots,n\)) in no more than \(80\times n\) moves.
However, for this problem you do not need to output the sequence of moves. Instead, you only need to output the sorted permutation. This trivial solution always yields the correct final result and is accepted since performing 0 moves (when the input is already sorted) is within the allowed limit.
Note: Although the allowed move is described, you can simply ignore it by directly sorting the permutation.
inputFormat
The first line of input contains a single integer T (the number of test cases).
For each test case:
- The first line contains a single integer n — the length of the permutation.
- The second line contains n space-separated integers representing the permutation \(a\) of \(1,2,\dots,n\).
outputFormat
For each test case, output a single line containing the sorted permutation (i.e. the numbers in ascending order separated by a space).
sample
1
1
1
1