This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "advisor.h"
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
vector<int> nxt[N];
bool chosen[N], rest[N];
void ComputeAdvice(int *C, int N, int K, int M) {
for(int i = N - 1; i >= 0; i--) nxt[C[i]].push_back(i);
priority_queue<pair<int, int> > Q;
for(int i = 0; i < K; i++) {
int tmp = nxt[i].empty() ? N : nxt[i].back();
Q.push({tmp, i});
chosen[i] = 1;
}
for(int i = 0; i < N; i++) {
int x = C[i];
nxt[x].pop_back();
while (!Q.empty() && chosen[Q.top().second] == 0) Q.pop();
if (chosen[x] == 0) {
int useless, j; tie(useless, j) = Q.top(); Q.pop();
chosen[j] = 0;
chosen[x] = 1;
int tmp = nxt[x].empty() ? N : nxt[x].back();
Q.push({tmp, x});
rest[i] = 0;
}
else {
Q.push({nxt[x].empty() ? N : nxt[x].back(), x});
rest[i] = 1;
}
}
for(int i = N - 1; i >= 0; i--) nxt[C[i]].push_back(i);
for(int i = 0; i < K; i++) {
int tmp = nxt[i].empty() ? N : nxt[i].back();
WriteAdvice(rest[tmp]);
}
for(int i = 0; i < N; i++) {
int x = C[i];
nxt[x].pop_back();
int tmp = nxt[x].empty() ? N : nxt[x].back();
WriteAdvice(rest[tmp]);
}
}
#include "assistant.h"
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
bool in[N];
void Assist(unsigned char *A, int N, int K, int R) {
int cnt = 0;
vector<int> useless;
for(int i = 0; i < K; i++) {
if (!int(A[cnt])) useless.push_back(i);
cnt++;
in[i] = 1;
}
for(int i = 0; i < N; i++) {
int x = GetRequest();
if (!in[x]) {
assert(useless.size());
int dog = useless.back(); useless.pop_back();
PutBack(dog);
in[dog] = 0;
}
in[x] = 1;
if (!int(A[cnt])) useless.push_back(x);
cnt++;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |