| Contests - ACM Student Chapter - PSUT |
|---|
| Private |
| Spectator |
| ZU JCPC Qualification 2026 |
|---|
| Finished |
Moon is playing a puzzle game designed by Aziz. Aziz gives him a permutation $$$a$$$ of length $$$n$$$.Moon can perform the following three-step operation on the permutation:
For example, if the permutation is $$$[1, 10, 4, 8, 7, 3, 5, 6, 2, 9]$$$ and Moon chooses a prefix of length $$$k=4$$$, the prefix $$$[1, 10, 4, 8]$$$ is reversed to $$$[8, 4, 10, 1]$$$ and moved to the back. The new permutation becomes $$$[7, 3, 5, 6, 2, 9, 8, 4, 10, 1]$$$. Note that if $$$n$$$ is chosen as the prefix length, the operation simply reverses the entire permutation.
Moon wants to sort the permutation in ascending order. He is looking for an efficient way to solve Aziz's puzzle. Help him find a sequence of at most $$$2n$$$ operations that sorts the permutation.
It can be shown that this is always possible
The first line of input contains a single integer $$$t$$$ ($$$1 \le t \le 5000$$$) — the number of test cases.
The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 5000$$$) — the length of the permutation $$$a$$$.
The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le n$$$) — the permutation $$$a$$$.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5000$$$.
For each test case, the first line of output should contain a single integer $$$q$$$ ($$$0 \le q \le 2n$$$) — the number of operations Moon will perform.
The second line should contain $$$q$$$ integers — the length of the prefix for each operation Moon performs, in order. After these operations, the permutation should be sorted.
If there are multiple valid solutions, you may print any of them.
253 2 1 5 431 2 3
84 1 1 2 3 1 1 531 1 1
| Name |
|---|

