# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
4740 | cki86201 | Last supper (IOI12_supper) | C++98 | 0 ms | 0 KiB |
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<queue>
using namespace std;
typedef pair<int,int> Pi;
#define X first
#define Y second
priority_queue <Pi> pq;
int next[100010],now[100010];
bool chk1[100010],chk2[100010],here[100010];
void ComputeAdvice(int *C, int N, int K, int M){
int i;
for(i=0;i<N;i++)now[i]=N;
for(i=N-1;i>=0;i--)next[i]=now[C[i]],now[C[i]]=i;
for(i=0;i<K;i++)pq.push(Pi(now[i],i)),here[i]=1;
for(i=0;i<N;i++)now[i]=-1;
for(i=0;i<N;i++){
if(!here[C[i]]){
Pi t=pq.top();
if(now[t.Y]==-1)chk1[t.Y]=1;
else chk2[now[t.Y]]=1;
pq.pop();
here[C[i]]=1,here[t.Y]=0;
}
pq.push(Pi(next[i],C[i]));
now[C[i]]=i;
}
for(i=0;i<K;i++)WriteAdvice(chk1[i]);
for(i=0;i<N;i++)WriteAdvice(chk2[i]);
}
#include"assistant.h"
int pos[100010],l;
bool in[100010];
void Assist(unsigned char *A, int N, int K, int R){
int i;
for(i=0;i<K;i++){
if(A[i])pos[++l]=i;
in[i]=1;
}
for(i=0;i<N;i++){
int t=GetRequest();
if(!in[t]){
PutBack(pos[l]);
in[t]=1,in[pos[l--]]=0;
}
if(A[i+K])pos[++l]=t;
}
}