#include<cstdio> #include<iostream> #include<cstring> #include<vector> #include<map> #include <string> #include<algorithm> using namespace std; int r[1005],w[1005]; vector<int>v[2]; int main() { int n,m,i,j,rk = 0,f = 0; scanf("%d%d",&n,&m); for(i = 0;i<n;i++)scanf("%d",&w[i]); for(i = 0;i<n;i++) { scanf("%d",&j); v[0].push_back(j); } while(1) { if(v[f].size() == 1) { r[v[f][0]] = 1; break; } rk = v[f].size()/m; if(v[f].size()%m)rk++; for(i = 0;i<v[f].size();i+=m) { int mx = -1; for(j = i;j<i+m&&j<v[f].size();j++)mx = max(w[v[f][j]],mx); for(j = i;j<i+m&&j<v[f].size();j++) { if(w[v[f][j]]==mx)v[1-f].push_back(v[f][j]); else r[v[f][j]] = rk+1; } } v[f].clear(); f = 1-f; } for(i = 0;i<n;i++) { printf("%d",r[i]); if(i!=n-1)printf(" "); } return 0; }