Problem:
Score : 2000 points

Problem Statement

You are given a permutation P_1 ... P_N of the set {1, 2, ..., N}.

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

Choose two indices i,j (1 ≦ i < j ≦ N), such that j - i ≧ K and |P_i - P_j| = 1.
Then, swap the values of P_i and P_j.

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

Constraints

2≦N≦500,000

1≦K≦N-1

P is a permutation of the set {1, 2, ..., N}.

Input

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

N K
P_1 P_2 ... P_N

Output

Print the lexicographically smallest permutation that can be obtained.

Sample Input 1

4 2
4 2 3 1

Sample Output 1

2
1
4
3

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

4 2 3 1

4 1 3 2

3 1 4 2

2 1 4 3

Sample Input 2

5 1
5 4 3 2 1

Sample Output 2

1
2
3
4
5

Sample Input 3

8 3
4 5 7 8 3 1 2 6

Sample Output 3

1
2
6
7
5
3
4
8

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

//2017-10-8
//miaomiao
//
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

#define pb push_back
#define For(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define Forr(i, a, b) for(int i = (a); i >= (int)(b); --i)

#define N (500000+5)

const int oo = 0x3f3f3f3f;

int n, a[N], ql, qr;

#define lc (o<<1)
#define rc (o<<1|1)
#define mid ((L+R)>>1)

namespace Seg_tree{
	int mn[N<<2];

	void Pushup(int o){
		mn[o] = min(mn[lc], mn[rc]);
	}

	void Build(int o, int L, int R){
		if(L == R){
			mn[o] = oo; return;
		}

		Build(lc, L, mid); Build(rc, mid+1, R);
		Pushup(o);
	}

	void Modify(int o, int L, int R, int p, int pv){
		if(L == R){
			mn[o] = pv; return;
		}

		if(p <= mid) Modify(lc, L, mid, p, pv);
		else Modify(rc, mid+1, R, p, pv);
		Pushup(o);
	}

	int Query(int o, int L, int R){
		if(ql <= L && qr >= R) return mn[o];

		int ret = oo;
		if(ql <= mid) ret = min(ret, Query(lc, L, mid));
		if(qr > mid) ret = min(ret, Query(rc, mid+1, R));
		return ret;
	}
};

#undef lc
#undef rc
#undef mid

using namespace Seg_tree;

int k, in[N], id[N], ans[N];
vector<int> G[N];

void EdgeInit(){
	int mv, qp;

	Forr(i, n, 1){
		mv = a[i];

		ql = max(mv-k+1, 1);  qr = max(mv-1, 0);
		if(ql <= qr){
			qp = Query(1, 1, n);
			if(qp != oo){
				G[a[qp]].pb(mv); ++in[mv];
			}
		}

		ql = min(mv+1, n); qr = min(mv+k-1, n+1);
		if(ql <= qr){
			qp = Query(1, 1, n);
			if(qp != oo){
				G[a[qp]].pb(mv); ++in[mv];
			}
		}

		Modify(1, 1, n, a[i], i);
	}
}

priority_queue<int> q;

void Solve(){
	For(i, 1, n) if(!in[i]) q.push(i);
	int now, v, an = 0;

	while(!q.empty()){
		now = q.top(); q.pop();
		id[++an] = now;

		For(i, 0, G[now].size()-1){
			v = G[now][i]; --in[v];
			if(!in[v]) q.push(v);
		}
	}

	reverse(id+1, id+n+1);
	For(i, 1, n) ans[id[i]] = i;

	For(i, 1, n) printf("%d\n", ans[i]);
}

int main(){
	int rt;

	scanf("%d%d", &n, &k);
	For(i, 1, n) scanf("%d", &rt), a[rt] = i;
	Build(1, 1, n);

	EdgeInit(); Solve();

	return 0;
}