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;
#define pb push_back
#define sz(x) (int) (x).size()
#define pii pair<int,int>
#define f first
#define s second
void ComputeAdvice(int *C, int N, int K, int M){
int last[N];
int cnext[N];
for (int i = 0; i < N; i++) last[i] = N;
for (int i = N-1; i >= 0; i--){
cnext[i] = last[C[i]];
last[C[i]] = i;
}
bool vis[N];
memset(vis,0,sizeof(vis));
set<pii> all;
int cidx[N];
for (int i = 0; i < K; i++){ all.insert((pii) {-last[i],i}); vis[i] = 1; cidx[i] = i;}
bool res[N+K];
memset(res,0,sizeof(res));
int c,t;
for (int i = 0; i < N; i++){
c = C[i];
if (vis[c]){
res[cidx[c]] = 1;
cidx[c] = i+K;
all.erase((pii) {i,c});
all.insert((pii) {-cnext[i],c});
continue;
}
cidx[c] = i+K;
t = (*all.begin()).s;
vis[t] = 0;
vis[c] = 1;
all.erase(all.begin());
all.insert((pii) {-cnext[i],c});
}
for (int i = 0; i < N+K; i++) WriteAdvice(res[i]);
return;
}
#include "assistant.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(x) (int) (x).size()
#define pii pair<int,int>
#define f first
#define s second
void Assist(unsigned char *A, int N, int K, int R){
stack<int> o;
bool vis[N];
memset(vis,0,sizeof(vis));
for (int i = 0; i < K; i++){
vis[i] = 1;
if (A[i] == 0) o.push(i);
}
int c,t;
for (int i = 0; i < N; i++){
c = GetRequest();
if (vis[c]){
if (A[i+K] == 0) o.push(c);
continue;
}
t = o.top();
o.pop();
vis[t] = 0;
PutBack(t);
vis[c] = 1;
if (A[i+K] == 0) o.push(c);
}
}
# | 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... |