#include "advisor.h"
#include<bits/stdc++.h>
using namespace std;
const int nn = 2e5 + 5;
vector<int> x[nn];
int cur[nn], save[nn], last[nn];
void ComputeAdvice(int *C, int N, int K, int M) {
for(int i = N - 1; i >= 0; i--) {
x[C[i]].push_back(i + K);
}
set<pair<int,int> > s;
for(int i = 0; i < K; i++) {
cur[i] = 1;
s.insert({x[i].size() ? x[i].back() : N, i});
if(x[i].size()) x[i].pop_back();
last[i] = i;
}
for(int i = K; i < N + K; i++) {
int c = C[i - K];
if(cur[c]) {
save[last[c]] = 1;
s.erase({i, c});
}
else {
pair<int,int> p = *--s.end();
s.erase(p);
cur[p.second] = 0;
}
cur[c] = 1;
s.insert({(x[c].size() ? x[c].back() : N), c});
if(x[c].size()) x[c].pop_back();
last[c] = i;
}
for(int i = 0; i < N + K; i++) WriteAdvice(save[i]);
}
#include<bits/stdc++.h>
using namespace std;
#include "assistant.h"
const int nn = 2e5 + 5;
int last[nn], cur[nn];
void Assist(unsigned char *A, int N, int K, int R) {
set<pair<int,int> > s;
for(int i = 0; i < K; i++) {
last[i] = i;
s.insert({A[i] - '0', i});
cur[i] = 1;
}
for(int i = K; i < N + K; i++) {
int c = GetRequest();
if(cur[c]) {
s.erase({A[last[c]] - '0', c});
last[c] = i;
s.insert({A[i] - '0', c});
continue;
}
cur[c] = 1;
pair<int,int> p = *s.begin();
assert(!p.first);
PutBack(p.second);
s.erase(p);
cur[p.second] = 0;
s.insert({A[i] - '0', c});
last[c] = i;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
5524 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
11 ms |
6492 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
86 ms |
14496 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
7 ms |
5928 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
100 ms |
16132 KB |
Execution killed with signal 6 |
2 |
Runtime error |
97 ms |
16284 KB |
Execution killed with signal 6 |
3 |
Runtime error |
136 ms |
16856 KB |
Execution killed with signal 6 |
4 |
Runtime error |
113 ms |
17128 KB |
Execution killed with signal 6 |
5 |
Runtime error |
102 ms |
16900 KB |
Execution killed with signal 6 |
6 |
Runtime error |
99 ms |
16908 KB |
Execution killed with signal 6 |
7 |
Runtime error |
102 ms |
16848 KB |
Execution killed with signal 6 |
8 |
Runtime error |
127 ms |
16900 KB |
Execution killed with signal 6 |
9 |
Runtime error |
129 ms |
17140 KB |
Execution killed with signal 6 |
10 |
Runtime error |
92 ms |
16912 KB |
Execution killed with signal 6 |