#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n,k;
int main(){
cin>>n>>k; vector<int>ord(n),wei(n),rnk(n);
for(auto&x:wei)cin>>x;
for(auto&x:ord)cin>>x;
while(ord.size()>1){
int grp=ord.size()/k+(ord.size()%k?1:0);
vector<int>_ord;
for(int i=0;i<grp;++i){
auto beg=ord.begin()+i*k,end=beg+k>=ord.end()?ord.end():beg+k;
for_each(beg,end,[&](int x){rnk[x]=grp+1;});
_ord.push_back(*max_element(beg,end,[&](int x,int y){return wei[x]<wei[y];}));
}//for
ord=_ord;
}//while
rnk[ord[0]]=1;
for(int i=0;i<n;++i) cout<<(i?" ":"")<<rnk[i];
}
1056. Mice and Rice
最新推荐文章于 2019-06-22 21:13:24 发布