#include <bits/stdc++.h>
#include "advisor.h"
using namespace std;
typedef pair<int,int> pii;
vector<int> nxt[100001],rem[100001];
bool have[100001],init[100001],ad[100001];
int n;
int go(int color,int cur){
vector<int>::iterator it = upper_bound(nxt[color].begin(),nxt[color].end(),cur);
if(it == nxt[color].end())
return n;
return *it;
}
bool active(int color , int idx){
int nxt = go(color,idx);
vector<int>::iterator it = upper_bound(rem[color].begin(),rem[color].end(),idx);
int nxR = 0;
if(it == rem[color].end())
nxR = n;
else
nxR = *it;
if(nxt < nxR)
return 1;
return 0;
}
void ComputeAdvice(int *C, int N, int K, int M) {
n = N;
for (int i = 0; i < N; ++i) {
nxt[C[i]].push_back(i);
}
set< pii > q;
for (int i = 0; i < K; ++i) {
have[i] = 1;
q.insert(make_pair(go(i, -1), i));
}
for (int i = 0; i < N; i++) {
int req = C[i];
if (have[req]) {
q.erase(make_pair(go(req, i - 1), req));
q.insert(make_pair(go(req, i), req));
continue;
}
pii src = (*(--q.end()));
q.erase(src);
rem[src.second].push_back(i);
have[src.second] = 0;
have[req] = 1;
q.insert(make_pair(go(req, i), req));
}
//cout << "INITIAL " << endl;
for (int i = 0; i < K; ++i){
WriteAdvice(active(i,-1));
// cout << "THERE " << active(i,-1) << endl;
}
//cout << "REQUESTS" << endl;
for (int i = 0; i < N; ++i){
WriteAdvice(active(C[i],i));
//cout << C[i] << " -> " << active(C[i],i) << endl;
}
}
#include <bits/stdc++.h>
#include "assistant.h"
using namespace std;
typedef pair<int,int> pii;
bool hold[100001],state[100001];
set<int> passive;
void Assist(unsigned char *A, int N, int K, int R) {
for (int i = 0; i < R; ++i){
if(i >= K){
state[i-K] = A[i];
}else{
hold[i] = 1;
if(A[i] == 0){
passive.insert(i);
}
}
}
for (int i = 0; i < N; ++i){
int req = GetRequest();
if(!hold[req]){
PutBack(*passive.begin());
hold[*passive.begin()] = 0;
hold[req] = 1;
passive.erase(passive.begin());
}
if(state[i] == 1){
passive.erase(req);
}else{
passive.insert(req);
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
9968 KB |
Output is correct |
2 |
Correct |
8 ms |
10336 KB |
Output is correct |
3 |
Correct |
9 ms |
10688 KB |
Output is correct |
4 |
Correct |
10 ms |
10688 KB |
Output is correct |
5 |
Correct |
13 ms |
10872 KB |
Output is correct |
6 |
Correct |
13 ms |
10936 KB |
Output is correct |
7 |
Correct |
15 ms |
10936 KB |
Output is correct |
8 |
Correct |
13 ms |
11464 KB |
Output is correct |
9 |
Correct |
13 ms |
11464 KB |
Output is correct |
10 |
Correct |
16 ms |
11464 KB |
Output is correct |
11 |
Correct |
14 ms |
11464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
11840 KB |
Output is correct |
2 |
Correct |
96 ms |
14712 KB |
Output is correct |
3 |
Correct |
220 ms |
25696 KB |
Output is correct |
4 |
Correct |
146 ms |
25696 KB |
Output is correct |
5 |
Correct |
175 ms |
25696 KB |
Output is correct |
6 |
Correct |
165 ms |
25696 KB |
Output is correct |
7 |
Correct |
194 ms |
25696 KB |
Output is correct |
8 |
Correct |
161 ms |
25696 KB |
Output is correct |
9 |
Correct |
108 ms |
25696 KB |
Output is correct |
10 |
Correct |
210 ms |
25696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
152 ms |
25696 KB |
Output is correct |
2 |
Correct |
198 ms |
25696 KB |
Output is correct |
3 |
Correct |
214 ms |
25696 KB |
Output is correct |
4 |
Correct |
198 ms |
25696 KB |
Output is correct |
5 |
Correct |
188 ms |
25696 KB |
Output is correct |
6 |
Correct |
225 ms |
25696 KB |
Output is correct |
7 |
Correct |
194 ms |
25696 KB |
Output is correct |
8 |
Correct |
184 ms |
26832 KB |
Output is correct |
9 |
Correct |
144 ms |
26832 KB |
Output is correct |
10 |
Correct |
198 ms |
26832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
26832 KB |
Output is correct |
2 |
Correct |
13 ms |
26832 KB |
Output is correct |
3 |
Correct |
12 ms |
26832 KB |
Output is correct |
4 |
Correct |
13 ms |
26832 KB |
Output is correct |
5 |
Correct |
15 ms |
26832 KB |
Output is correct |
6 |
Correct |
13 ms |
26832 KB |
Output is correct |
7 |
Correct |
19 ms |
26832 KB |
Output is correct |
8 |
Correct |
14 ms |
26832 KB |
Output is correct |
9 |
Correct |
15 ms |
26832 KB |
Output is correct |
10 |
Correct |
21 ms |
26832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
197 ms |
26832 KB |
Output is correct - 120000 bits used |
2 |
Correct |
191 ms |
26832 KB |
Output is correct - 122000 bits used |
3 |
Correct |
203 ms |
26832 KB |
Output is correct - 125000 bits used |
4 |
Correct |
194 ms |
26832 KB |
Output is correct - 125000 bits used |
5 |
Correct |
205 ms |
26832 KB |
Output is correct - 125000 bits used |
6 |
Correct |
196 ms |
26832 KB |
Output is correct - 125000 bits used |
7 |
Correct |
199 ms |
26832 KB |
Output is correct - 124828 bits used |
8 |
Correct |
199 ms |
26832 KB |
Output is correct - 124910 bits used |
9 |
Correct |
191 ms |
26832 KB |
Output is correct - 125000 bits used |
10 |
Correct |
172 ms |
26832 KB |
Output is correct - 125000 bits used |