-
Notifications
You must be signed in to change notification settings - Fork 0
/
1056.cpp
85 lines (85 loc) · 2.07 KB
/
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//
// main.cpp
// test
//
// Created by 李寻欢 on 2019/10/7.
// Copyright © 2019 李寻欢. All rights reserved.
//
#include <stdio.h>
#include <iostream>
#include <string>
#include <map>
#include <cmath>
#include <algorithm>
#include <stack>
#include <vector>
#include <queue>
#include <unordered_map>
#include <string.h>
#include <set>
using namespace std;
const int MAXN = 1e3+10;
int n,g;
int weight[MAXN];
int ans[MAXN] = {0};
int main(){
scanf("%d%d",&n,&g);
queue<int> q;
queue<int> other;
for(int i=0;i<n;++i) scanf("%d",&weight[i]);
for(int i=0;i<n;++i){
int t;
scanf("%d",&t);
q.push(t);
}
while (q.size() != 1) {
int cur;
int now_max=-1,now_idx = -1;
int times = (int)q.size() / g;
int rest = (int)q.size() % g;
int rank = times+1;
if(rest) rank++;
while (times--) {
for(int i=0;i<g;++i){
cur = q.front();
q.pop();
other.push(cur);
if(weight[cur] > now_max){
now_max = weight[cur];
now_idx = cur;
}
}
q.push(now_idx);
while (other.size()) {
cur = other.front();
other.pop();
if(cur == now_idx) continue;
ans[cur] = rank;
}
now_max = now_idx = -1;
}
if(rest != 0){ // 这里去掉就超时了
while (rest--) {
cur = q.front();
q.pop();
other.push(cur);
if(weight[cur] > now_max){
now_max = weight[cur];
now_idx = cur;
}
}
q.push(now_idx);
while (other.size()) {
cur = other.front();
other.pop();
if(cur == now_idx) continue;
ans[cur] = rank;
}
}
}
ans[q.front()] = 1;
for(int i=0;i<n;++i){
printf("%d",ans[i]);
if(i != n-1) printf(" ");
}
}