-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA1056.cpp
60 lines (60 loc) · 1.27 KB
/
A1056.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include<iostream>
#include<queue>
#include <cmath>
#include<vector>
using namespace std;
struct S
{
int id;
int w;
int r;
};
int main()
{
int n,m;
cin>>n>>m;
vector<S> v;
for(int i = 0;i<n;i++){
S s;
cin >>s.w;
s.id=i;
v.push_back(s);
}
queue<S> q;
for(int i = 0; i< n;i++){
int tmp;
cin>>tmp;
q.push(v[tmp]);
}
while(q.size()!=1){
queue<S> tmp_q;
int out = ceil(q.size()/(double)m);
while(q.size()){
vector<S> group;
int max_w = 0;
int max_i;
for(int i = 0;i<m&&q.size();i++){
group.push_back(q.front());
q.pop();
}
for(int i = 0;i<group.size();i++){
if(max_w<group[i].w){
max_w = group[i].w;
max_i = group[i].id;
}
}
tmp_q.push(v[max_i]);
for(int i = 0;i<group.size();i++){
if(group[i].w!=max_w){
v[group[i].id].r=out+1;
}
}
}
q = tmp_q;
}
v[q.front().id].r = 1;
for(int i = 0;i<v.size();i++){
cout << v[i].r;
if(i<v.size()-1)cout<< " ";
}
}