#include<bits/stdc++.h>
using namespace std;
const int MAXN=1003;
struct Node{
int id;
int weight;
int rank;
int flag;//用于辨别属于哪一级别
}node[MAXN];
bool cmp(Node a,Node b){
return a.weight>b.weight;
}
bool cmp1(Node a,Node b){
return a.flag>b.flag;
}
bool cmp2(Node a,Node b){
return a.id<b.id;
}
int main()
{
freopen("in.txt","r",stdin);
int n,k;cin>>n>>k;
vector<int> ppp;
for(int i=0;i<n;i++){
cin>>node[i].weight;
node[i].id=i;
}
ppp.resize(n);
for(int i=0;i<n;i++){
cin>>ppp[i];
}
int num=0;
while(1){
vector<int> temp1;
vector<Node> temp;
for(int i=0;i<ppp.size();i+=k){//分组处理
for(int j=i;j<i+k&&j<ppp.size();j++){
temp.push_back(node[ppp[j]]);
}
sort(temp.begin(),temp.end(),cmp);
temp1.push_back(temp[0].id);
for(int j=1;j<temp.size();j++){
node[temp[j].id].flag=num;
}
temp.clear();
}
num++;
ppp.clear();
ppp=temp1;//记录下一个阶段的下标
if(ppp.size()==1){
node[ppp[0]].flag=num;break;
}
}
sort(node,node+n,cmp1);
node[0].rank=1;
for(int i=1;i<n;i++){
if(node[i].flag==node[i-1].flag) node[i].rank=node[i-1].rank;
else node[i].rank=i+1;
}
sort(node,node+n,cmp2);
for(int i=0;i<n;i++){
if(i==0) cout<<node[i].rank;
else cout<<' '<<node[i].rank;
}
return 0;
}