#include<iostream>
#include<queue>
using namespace std;
class mouse{
public:
int weight, rank, num;
};
int main(){
queue<mouse> q;
int i, j, np, ng, temp, groups;
scanf("%d%d", &np, &ng);
mouse m[np];
for(i = 0; i < np; i++){
scanf("%d", &m[i].weight);
m[i].num = i;
}
for(i = 0; i < np; i++){
scanf("%d", &temp);
q.push(m[temp]);
}
while(q.size() > 1){
int size = q.size();
if(q.size() % ng == 0){
groups = size / ng;
} else{
groups = q.size() / ng + 1;
}
for(i = 0; i < size; i += ng){
mouse win;
win.weight = -1;
for(j = i; j < i + ng && j < size; j++){
if(q.front().weight > win.weight){
win = q.front();
}
q.front().rank = groups + 1;
m[q.front().num] = q.front();
q.pop();
}
q.push(win);
}
}
q.front().rank = 1;
m[q.front().num] = q.front();
q.pop();
for(i = 0; i < np; i++){
printf("%d", m[i].rank);
if(i < np - 1) printf(" ");
}
return 0;
}
A1056
最新推荐文章于 2020-02-15 19:27:51 发布