-
Notifications
You must be signed in to change notification settings - Fork 0
/
1056.cpp
48 lines (47 loc) · 953 Bytes
/
1056.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
#include <bits/stdc++.h>
using namespace std;
struct person{
int id, w, order, rank;
};
bool cmpById(const person &a, const person &b){
return a.id < b.id;
}
int main(){
ios::sync_with_stdio(false);
int n, m;
cin>>n>>m;
vector<person> in(n), v(n);
vector<int> turn(n);
for(int i=0; i<n; i++){
turn[i] = i;
in[i].id = i;
cin>>in[i].w;
}
for(int i=0; i<n; i++){
int order;
cin>>order;
v[i] = in[order];
}
while(turn.size() != 1){
vector<int> winner;
int rank = ceil(turn.size()/(double)m) + 1;
for(int i=0; i<turn.size(); i+=m){
int maxw = v[turn[i]].w, maxid = turn[i];
for(int j=i; j<turn.size() && j-i<m; j++){
if(v[turn[j]].w > maxw){
maxw = v[turn[j]].w;
maxid = turn[j];
}
v[turn[j]].rank = rank;
}
winner.push_back(maxid);
}
turn = winner;
}
v[turn[0]].rank = 1;
sort(v.begin(), v.end(), cmpById);
for(int i=0; i<n; i++){
cout<<(i==0?"":" ")<<v[i].rank;
}
return 0;
}