#include <bits/stdc++.h>
#define ll long long
#define db long double
#define II pair <ll,ll>
#define III pair <ll,II>
#define IV pair <vector <int>,vector <int> >
#define fst first
#define snd second
#define BIT(x,i) ((x>>i)&1)
#define pi acos(-1)
#define to_radian(x) (x*pi/180.0)
#define to_degree(x) (x*180.0/pi)
#define Log(x) (31-__builtin_clz((int)x))
#define LogLL(x) (63-__builtin_clzll((ll)x))
#define N 200005
#include "advisor.h"
//#define WriteAdvice(k) cout<<k<<'\n';
using namespace std;
struct International_Olympiad_in_Informatics
{
int nxt[N],request[N],i,k,n,m,c[N],pos[N],res[N],now[N];
void Work(int c[],int n,int k,int m)
{
m=0;
for(i=1;i<=k;i++) request[++m]=i;
for(i=1;i<=n;i++) request[++m]=c[i];
memset(pos,63,sizeof(pos));
for(i=m;i>=1;i--) nxt[i]=pos[request[i]],pos[request[i]]=i;
set <II> s;
for(i=1;i<=m;i++)
{
int x=request[i];
// cout<<x<<" ";
if(i<=k) s.insert({ nxt[i],x });
else if(s.find({ i,x })!=s.end())
{
s.erase({ i,x });
s.insert({ nxt[i],x });
}
else
{
set <II>::iterator it=s.end(); it--;
II tg=*it; s.erase(tg);
res[now[tg.snd]]=1;
s.insert({ nxt[i],x });
// cerr<<tg.snd<<" "<<x<<'\n';
}
now[x]=i;
}
// cout<<'\n';
}
} IOI;
int n,k,m,c[N],i;
void ComputeAdvice(int _c[],int n,int k,int m)
{
for(int i=n;i>=1;i--) c[i]=_c[i-1],c[i]++;
IOI.Work(c,n,k,m);
for(int i=1;i<=n+k;i++) WriteAdvice(IOI.res[i]);
}
/*
int main()
{
freopen("advisor.inp","r",stdin);
freopen("advisor.out","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin>>n>>k>>m;
for(i=0;i<n;i++) cin>>c[i];
ComputeAdvice(c,n,k,m);
}
*/
#include <bits/stdc++.h>
#define ll long long
#define db long double
#define II pair <ll,ll>
#define III pair <ll,II>
#define IV pair <vector <int>,vector <int> >
#define fst first
#define snd second
#define BIT(x,i) ((x>>i)&1)
#define pi acos(-1)
#define to_radian(x) (x*pi/180.0)
#define to_degree(x) (x*180.0/pi)
#define Log(x) (31-__builtin_clz((int)x))
#define LogLL(x) (63-__builtin_clzll((ll)x))
#define N 200005
#include "assistant.h"
//#define PutBack(x) cout<<x<<'\n';
using namespace std;
struct International_Olympiad_in_Informatics
{
int n,k,m,i,in[N];
unsigned char a[N];
set <int> s;
void Init(unsigned char _a[],int _n,int _k,int _m)
{
n=_n; k=_k; m=_m;
for(i=1;i<=m;i++) a[i]=_a[i];
}
int add(int i,int x)
{
if(i<=k)
{
// cerr<<i<<" "<<a[i]<<'\n';
if(a[i]==1) s.insert(x);
in[x]=1;
return 0;
}
else if(in[x]==1)
{
s.erase(x);
if(a[i]==1) s.insert(x);
in[x]=1;
return 0;
}
else
{
int y=*s.begin(); s.erase(y);
in[y]=0;
if(a[i]==1) s.insert(x);
in[x]=1;
return y;
}
}
} IOI;
//int GetRequest() { int k; cin>>k; return k; }
int n,k,r,i;
unsigned char a[N];
void Assist(unsigned char _a[], int n, int k, int r)
{
for(i=r;i>=1;i--) a[i]=_a[i-1];
IOI.Init(a,n,k,r);
for(i=1;i<=k;i++) IOI.add(i,i);
for(i=k+1;i<=k+n;i++)
{
int x=GetRequest(),k=IOI.add(i,x+1);
// cerr<<i<<" "<<k-1<<'\n';
if(k>0) PutBack(k-1);
}
}
/*
int main()
{
freopen("assist.inp","r",stdin);
freopen("assist.out","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin>>n>>k>>r;
for(i=0;i<r;i++) cin>>a[i];
Assist(a,n,k,r);
}
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4892 KB |
Output is correct |
2 |
Correct |
1 ms |
4892 KB |
Output is correct |
3 |
Correct |
1 ms |
4900 KB |
Output is correct |
4 |
Correct |
3 ms |
4916 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4936 KB |
Output is correct |
7 |
Correct |
4 ms |
5204 KB |
Output is correct |
8 |
Correct |
4 ms |
5196 KB |
Output is correct |
9 |
Correct |
4 ms |
5204 KB |
Output is correct |
10 |
Correct |
4 ms |
5300 KB |
Output is correct |
11 |
Correct |
4 ms |
5196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
5480 KB |
Output is correct |
2 |
Correct |
33 ms |
7780 KB |
Output is correct |
3 |
Correct |
74 ms |
12520 KB |
Output is correct |
4 |
Correct |
48 ms |
9992 KB |
Output is correct |
5 |
Correct |
52 ms |
10144 KB |
Output is correct |
6 |
Correct |
63 ms |
10268 KB |
Output is correct |
7 |
Correct |
74 ms |
11580 KB |
Output is correct |
8 |
Correct |
54 ms |
10876 KB |
Output is correct |
9 |
Correct |
47 ms |
9552 KB |
Output is correct |
10 |
Correct |
84 ms |
12364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
9640 KB |
Output is correct |
2 |
Correct |
75 ms |
11872 KB |
Output is correct |
3 |
Correct |
79 ms |
12020 KB |
Output is correct |
4 |
Correct |
78 ms |
11864 KB |
Output is correct |
5 |
Correct |
79 ms |
11916 KB |
Output is correct |
6 |
Correct |
75 ms |
12012 KB |
Output is correct |
7 |
Correct |
75 ms |
11932 KB |
Output is correct |
8 |
Correct |
65 ms |
11824 KB |
Output is correct |
9 |
Correct |
66 ms |
12280 KB |
Output is correct |
10 |
Correct |
77 ms |
11992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5176 KB |
Output is correct |
2 |
Correct |
5 ms |
5192 KB |
Output is correct |
3 |
Correct |
3 ms |
4944 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
4 ms |
4940 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
4 ms |
5196 KB |
Output is correct |
8 |
Correct |
5 ms |
5204 KB |
Output is correct |
9 |
Correct |
4 ms |
5196 KB |
Output is correct |
10 |
Correct |
5 ms |
5204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
72 ms |
10496 KB |
Output is correct - 120000 bits used |
2 |
Correct |
78 ms |
10476 KB |
Output is correct - 122000 bits used |
3 |
Correct |
75 ms |
10748 KB |
Output is correct - 125000 bits used |
4 |
Correct |
76 ms |
10744 KB |
Output is correct - 125000 bits used |
5 |
Correct |
76 ms |
10884 KB |
Output is correct - 125000 bits used |
6 |
Correct |
75 ms |
10792 KB |
Output is correct - 125000 bits used |
7 |
Correct |
76 ms |
10832 KB |
Output is correct - 124828 bits used |
8 |
Correct |
75 ms |
10808 KB |
Output is correct - 124910 bits used |
9 |
Correct |
76 ms |
10796 KB |
Output is correct - 125000 bits used |
10 |
Correct |
66 ms |
10488 KB |
Output is correct - 125000 bits used |