| Codeforces Round 1084 (Div. 3) |
|---|
| Finished |
You are given a permutation$$$^{\text{∗}}$$$ $$$p$$$ of length $$$n$$$. There are also two portals located at positions $$$x$$$ and $$$y$$$ ($$$x \lt y$$$).
A portal at position $$$i$$$ is initially located between the $$$i$$$-th and $$$(i+1)$$$-th elements of the array. Specifically, if $$$i=0$$$, then the portal is located before the first element of the array, and if $$$i=n$$$, then the portal is located after the last element.
You may perform either of the following two operations as many times as you like:
Let $$$\mathbf{\color{red}{\mathcal{O}}}$$$ denote a portal. For example, if $$$p$$$ is $$$[3,\mathbf{\color{red}{\mathcal{O}}},2,4,\mathbf{\color{red}{\mathcal{O}}},1]$$$:
Find the lexicographically$$$^{\text{†}}$$$ smallest permutation you can obtain using these operations. Note that portals do not affect the lexicographical comparison of permutations.
$$$^{\text{∗}}$$$A permutation of length $$$n$$$ is an array of length $$$n$$$ containing each integer from $$$1$$$ to $$$n$$$ exactly once.
$$$^{\text{†}}$$$A permutation $$$a$$$ is lexicographically smaller than permutation $$$b$$$ if there exists an index $$$i$$$ such that $$$a_j = b_j$$$ for all indices $$$1 \leq j \lt i$$$ and $$$a_i \lt b_i$$$.
The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 2\cdot 10^4$$$) — the number of test cases.
For each test case, the first line contains three integers $$$n$$$, $$$x$$$, and $$$y$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$, $$$0 \leq x \lt y \leq n$$$).
The second line of each test case contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ — a permutation of length $$$n$$$.
The sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, output a line with $$$n$$$ integers — the lexicographically smallest permutation you can obtain.
44 0 43 1 4 23 1 23 2 15 1 31 3 5 2 42 0 11 2
1 4 2 32 3 11 2 3 5 41 2
Let $$$\mathbf{\color{red}{\mathcal{O}}}$$$ denote a portal.
In the first test case, the array is $$$[\mathbf{\color{red}{\mathcal{O}}},3,1,4,2,\mathbf{\color{red}{\mathcal{O}}}]$$$. Using operation $$$2$$$ on the left portal results in $$$[\mathbf{\color{red}{\mathcal{O}}},1,4,2,3,\mathbf{\color{red}{\mathcal{O}}}]$$$, which is the lexicographically smallest possible permutation that can be obtained.
The operation described above. In the second test case, the array is $$$[3,\mathbf{\color{red}{\mathcal{O}}},2,\mathbf{\color{red}{\mathcal{O}}},1]$$$. Using operation $$$1$$$ on the left portal results in $$$[\mathbf{\color{red}{\mathcal{O}}},2,\mathbf{\color{red}{\mathcal{O}}},3,1]$$$, which is the lexicographically smallest possible permutation that can be obtained.
In the fourth test case, it is optimal not to do any operations.
| Name |
|---|


