| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 (추가 시간 없음) | 1024 MB | 154 | 109 | 104 | 77.037% |
A permutation is called irreducible if none of its prefixes forms a permutation, except the permutation itself. For example, $[2,3,1]$ and $[4,1,2,3]$ are irreducible while $[2,1,3]$ and $[1,3,2]$ are not.
You are given a permutation $P$ of length $N$. In one operation, you can choose any two adjacent indices and swap their values.
Find the minimum number, and the corresponding sequence, of operations to transform $P$ into an irreducible permutation. It can be shown that you can always make given permutation irreducible.
The first line contains a single integer $T$ --- the number of test cases.
The first line of each test case contains a single integer $N$.
The second line of each test case contains $N$ space-separated integers $P_1,\ldots ,P_N$ $(1\le P_i\le N)$.
For each test case, print two lines:
On the first line, print $K$ --- the minimum number of operations that can make $P$ irreducible.
On the second line, print $K$ space-separated integers $S_1,\ldots ,S_K$ where $S_i$ and $S_i+1$ are the indices you intend to swap. If there are multiple solutions, you may print any.
Note that the operations are performed sequentially in the same order specified by your output.
3 4 1 2 3 4 3 2 3 1 5 3 1 2 4 5
3 1 2 3 0 2 4 3