Upload code_segments/segment_95.txt with huggingface_hub
Browse files- code_segments/segment_95.txt +27 -0
code_segments/segment_95.txt
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The secret behind Oscar's first magic trick has been revealed! Because he still wants to impress Lura, he comes up with a new idea: he still wants to sort a permutation $p_1, p_2, \ldots, p_n$ of $[1, 2, \ldots, n]$.
|
| 2 |
+
|
| 3 |
+
This time, he chooses an integer $k$. He wants to sort the permutation in non-decreasing order using the following operation several times:
|
| 4 |
+
|
| 5 |
+
1. Pick a continuous subarray of length $k$ and remove it from $p$. 2. Insert the continuous subarray back into $p$ at any position (perhaps, in the very front or the very back).
|
| 6 |
+
|
| 7 |
+
To be as impressive as possible, Oscar would like to choose the maximal value of $k$ such that he can sort his permutation. Please help him find the maximal $k$ as well as a sequence of operations that will sort the permutation. You don't need to minimize the number of operations, but you are allowed to use at most $5n^2$ operations.
|
| 8 |
+
|
| 9 |
+
We have a proof that, for the maximal $k$ such that you can sort the permutation in any number of operations, you can also sort it in at most $5n^2$ operations.
|
| 10 |
+
|
| 11 |
+
The first line contains a single integer $t$ ($1 \leq t \leq 10^3$) — the number of test cases.
|
| 12 |
+
|
| 13 |
+
The first line of each test case contains a single integer $n$ ($5 \leq n \leq 10^3$) — the length of the permutation.
|
| 14 |
+
|
| 15 |
+
The second line of each test case contains a permutation $p_1, p_2, \ldots, p_n$ of $[1, 2, \ldots, n]$.
|
| 16 |
+
|
| 17 |
+
The sum of $n$ over all test cases does not exceed $2 \cdot 10^3$.
|
| 18 |
+
|
| 19 |
+
For each test case, first output the chosen value of $k$ on a new line ($1 \leq k \leq n$).
|
| 20 |
+
|
| 21 |
+
Then, output a single integer $m$ — the number of operations used ($0 \leq m \leq 5n^2$).
|
| 22 |
+
|
| 23 |
+
Then, on each of the next $m$ lines, output the operations denoted by two integers $i$ and $j$ ($1 \leq i, j \leq n - k + 1$), representing an operation where you remove the subarray starting from index $i$ and replace it back into $p$ at index $j$.
|
| 24 |
+
|
| 25 |
+
In the first test case, it is enough to move the last four numbers to the front.
|
| 26 |
+
|
| 27 |
+
In the second test case, it can be shown that we cannot have $k = 4$ or $k = 5$. With $k =
|