atcoder#AGC001F. [AGC001F] Wide Swap

[AGC001F] Wide Swap

Score : 20002000 points

Problem Statement

You are given a permutation P1...PNP_1 ... P_N of the set {11, 22, ..., NN}.

You can apply the following operation to this permutation, any number of times (possibly zero):

  • Choose two indices i,j(1i<jN)i,j (1 \leq i < j \leq N), such that jiKj - i \geq K and PiPj=1|P_i - P_j| = 1. Then, swap the values of PiP_i and PjP_j.

Among all permutations that can be obtained by applying this operation to the given permutation, find the lexicographically smallest one.

Constraints

  • 2N500,0002 \leq N \leq 500,000
  • 1KN11 \leq K \leq N-1
  • PP is a permutation of the set {11, 22, ..., NN}.

Input

The input is given from Standard Input in the following format:

NN KK

P1P_1 P2P_2 ...... PNP_N

Output

Print the lexicographically smallest permutation that can be obtained.

4 2
4 2 3 1
2
1
4
3

One possible way to obtain the lexicographically smallest permutation is shown below:

  • 42314 2 3 1
  • 41324 1 3 2
  • 31423 1 4 2
  • 21432 1 4 3
5 1
5 4 3 2 1
1
2
3
4
5
8 3
4 5 7 8 3 1 2 6
1
2
6
7
5
3
4
8