题目描述
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given an integer $K$ and a random permutation ― sequence $A_{1}, A_{2}, \ldots, A_{N}$ of integers $1$ through $N$. You have to perform the following process:
1. Split the permutation $A$ into $K$ non-empty contiguous subsequences $S_{1}, S_{2}, \dots, S_{K}$ such that each element of $A$ appears in exactly one of them.
2. Choose an arbitrary permutation $P$ of the integers $1$ through $K$.
3. Create a new permutation $B_{1}, B_{2}, \ldots, B_{N}$ by concatenating the sequences $S_{P_{1}}, S_{P_{2}}, \ldots, S_{P_{K}}$ in this order.
You are allowed to split the permutation $A$ into $K$ subsequences in any valid way and choose any permutation $P$ you want. Your goal is to make the length of the longest increasing subsequence of the permutation $B$ as large as possible.
------ Input ------
The first line of the input contains two space-separated integers $N$ and $K$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.
------ Output ------
Print a single line containing $N$ space-separated integers $B_{1}, B_{2}, \ldots, B_{N}$.
------ Constraints ------
$5 ≤ N ≤ 5 \cdot 10^{5}$
$3 ≤ K ≤ N$
$1 ≤ A_{i} ≤ N$ for each valid $i$
$A_{i} \neq A_{j}$ for each valid $i, j$ ($i \neq j$)
------ Scoring ------
In each test case (and therefore each test file), let $L_{A}$ and $L_{B}$ be the lengths of the longest increasing subsequences of the permutations $A$ and $B$ respectively. If $L_{B} ≤ L_{A}$, your submission will receive the Wrong Answer verdict. Otherwise, your score for this test case is $(L_{B} - L_{A}) \cdot W$, where $W$ is a parameter of the grader. The values of $W$ for all tests are specified in the Test Generation section. The score of a submission is equal to the sum of its scores over all test cases. The goal is to maximise the score of your submission.
There are 18 test files. During the contest, the displayed score will account for exactly five test files (belonging to groups 1, 3, 5, 7, 9 from the test generation section), i.e. your score reflects your submission's performance on roughly 28% (5 / 18) of the test files. However, if your program gets a non-AC verdict on any test file, your submission's verdict will be non-AC. In other words, an AC verdict denotes that your program runs successfully on all the test files. After the end of the contest, your score will be changed to include the sum of your program's scores over the other $13$ test files.
------ Example Input ------
7 3
5 3 7 1 2 6 4
------ Example Output ------
1 2 6 4 5 3 7
------ Explanation ------
The permutation $B = (1, 2, 6, 4, 5, 3, 7)$ could be obtained from $A = (5, 3, 7, 1, 2, 6, 4)$ in the following way:
1. Choose subsequences $S_{1} = (5, 3)$, $S_{2} = (7)$, $S_{3} = (1, 2, 6, 4)$.
2. Choose the permutation $P = (3, 1, 2)$.
3. Concatenate $S_{P_{1}}, S_{P_{2}}, S_{P_{3}} = S_{3}, S_{1}, S_{2} = (1, 2, 6, 4), (5, 3), (7)$.
The longest increasing subsequence of $A$ is $(1, 2, 6)$ and its length is $L_{A} = 3$. The longest increasing subsequence of $B$ is $(1, 2, 4, 5, 7)$ and its length is $L_{B} = 5$. If $W = 1$, the final score of this solution on this test case is $L_{B} - L_{A} = 5 - 3 = 2$.
------ Test generation ------
There are nine test groups. In each test group, there are two test cases; the values of $N$, $K$ and $W$ (the scoring coefficient) are listed in the table below. In each test case, the permutation $A$ is chosen uniformly randomly among all $N!-1$ permutations other than $1, 2, \ldots, N-1, N$.
Group
N
K
W
1
5 · 10^{3}
50
8284
2
5 · 10^{3}
140
4745
3
5 · 10^{3}
400
2124
4
5 · 10^{4}
150
2676
5
5 · 10^{4}
450
1484
6
5 · 10^{4}
1500
580
7
5 · 10^{5}
500
828
8
5 · 10^{5}
1400
474
9
5 · 10^{5}
5000
175
输入格式
见题面
输出格式
见题面