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)

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<queue>
#include<set>
#define rep(i,s,t) for(register int i=s;i<=t;++i)
#define _rep(i,s,t) for(register int i=s;i>=t;--i)
#define Rep(i,s,t) for(register int i=s;i<t;++i)
#define go(x) for(register int e=las[x];e;e=nxt[e])
#define re register
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define gi(x) read(x)
#define gii(x,y) read(x),read(y)
#define giii(x,y,z) read(x),read(y),read(z)
#define ms(f,x) memset(f,x,sizeof f)
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
namespace IO{
    #define gc getchar()
    #define pc(x) putchar(x)
    template<typename T>inline void read(T &x){
        x=0;int f=1;char ch=gc;while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=gc;}
        while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=gc;x*=f;return;
    }
    template<typename T>inline void write(T x=0){
        T wr[51];wr[0]=0;if(x<0)pc('-'),x=-x;if(!x)pc(48);
        while(x)wr[++wr[0]]=x%10,x/=10;while(wr[0])pc(48+wr[wr[0]--]);return;
    }
}
using IO::read; 
using namespace std;
const int N=2e6+11;
int n,k,tot,x;
int p[N],q[N],mx[N];
//p=q^(-1)
set<pii>s;
set<pii> :: iterator it;
priority_queue<int>heap;
int nxt[N],las[N],to[N],deg[N];
inline void add(int x,int y){
	nxt[++tot]=las[x];
	las[x]=tot;
	to[tot]=y;
	++deg[y];
}
inline void topsort(){
	rep(i,1,n)
		if(!deg[i])
			heap.push(-i);
	rep(i,1,n){
		int x=-heap.top();heap.pop();
		p[x]=i;
		go(x){
			--deg[to[e]];
			if(!deg[to[e]])
				heap.push(-to[e]); 
		} 
	}
}
#define lson k<<1,l,mid
#define rson k<<1|1,mid+1,r
inline void ins(int x,int p,int k=1,int l=1,int r=n){
	if(l==r){
		mx[k]=p;
		return ;
	}
	int mid=(l+r)>>1;
	x<=mid?ins(x,p,lson):ins(x,p,rson);
	mx[k]=max(mx[k<<1],mx[k<<1|1]);
}
inline int query(int x,int y,int k=1,int l=1,int r=n){
	if(x<=l&&r<=y)return mx[k];
	int mid=(l+r)>>1;
	int ans=0;
	if(x<=mid)ans=query(x,y,lson);
	if(mid<y)ans=max(ans,query(x,y,rson));
	return ans;
}
int main(){
	gii(n,k);
	rep(i,1,n){ 
		gi(p[i]);
		q[p[i]]=i;
	}
	//rep(i,1,n)printf("%d ",q[i]);puts("");
	rep(i,1,n){
		//printf("%d %d\n",i,q[i]);
		x=query(q[i],min(q[i]+k-1,n));
		if(x)add(q[x],q[i]);
		x=query(max(q[i]-k+1,1),q[i]);
		if(x)add(q[x],q[i]);
		//printf("%d\n",x);
		ins(q[i],i);
	}
	//rep(i,1,n)printf("%d ",deg[i]);puts("");
	topsort(); 
	rep(i,1,n)
		printf("%d\n",p[i]);
	return 0;
}