#include "advisor.h"
#include<bits/stdc++.h>
using namespace std;
const int nmax=2e5+42;
int seen[nmax];
int nxt_seen[nmax];
set< pair<int/*seen next*/,int/*id*/> > s;
int when_pushed[nmax];
set<int> cut_moment[nmax];
vector<int> there[nmax];
int check_next_moment(int pos,int after)
{
if(there[pos].size()==0)return 0;
int p=upper_bound(there[pos].begin(),there[pos].end(),after)-there[pos].begin();
p=there[pos][p];
set<int>::iterator it=cut_moment[pos].upper_bound(after);
int q=*it;
//cout<<pos<<" "<<after<<" "<<p<<" "<<q<<endl;
return p<q;
}
void ComputeAdvice(int *C,int N,int K,int M)
{
for(int i=0;i<N;i++)
seen[i]=N;
for(int i=N-1;i>=0;i--)
{
nxt_seen[i]=seen[C[i]];
seen[C[i]]=i;
}
for(int i=0;i<K;i++)
s.insert({seen[i],i});
for(int i=0;i<N;i++)
if(s.count({i,C[i]}))
{
s.erase({i,C[i]});
s.insert({nxt_seen[i],C[i]});
}
else
{
//cut the furthest
set< pair<int/*seen next*/,int/*id*/> >::iterator it=s.end();
it--;
int which=(*it).second;
cut_moment[which].insert(i);
//cout<<"pushed cut moment "<<which<<" "<<i<<endl;
when_pushed[C[i]]=i;
s.erase(it);
s.insert({nxt_seen[i],C[i]});
}
for(int i=0;i<N;i++)
there[C[i]].push_back(i);
for(int i=0;i<N;i++)
{
cut_moment[i].insert(N);
there[i].push_back(N);
}
for(int i=0;i<K;i++)
WriteAdvice(check_next_moment(i,-1));
for(int i=0;i<N;i++)
WriteAdvice(check_next_moment(C[i],i));
}
#include "assistant.h"
#include<bits/stdc++.h>
using namespace std;
const int nmax=2e5+42;
set<int> active,passive;
void Assist(unsigned char *A, int N, int K, int R)
{
for(int i=0;i<K;i++)
if(A[i]==1)active.insert(i);
else passive.insert(i);
for(int i=K;i<N+K;i++)
{
int cur=GetRequest();
if(active.count(cur))
{
active.erase(cur);
}
else
{
assert(passive.size());
int tp=*passive.begin();
passive.erase(tp);
PutBack(tp);
}
if(A[i]==1)active.insert(cur);
else passive.insert(cur);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
28928 KB |
Output is correct |
2 |
Correct |
8 ms |
29184 KB |
Output is correct |
3 |
Correct |
9 ms |
29184 KB |
Output is correct |
4 |
Correct |
12 ms |
29696 KB |
Output is correct |
5 |
Correct |
15 ms |
30464 KB |
Output is correct |
6 |
Correct |
14 ms |
30464 KB |
Output is correct |
7 |
Correct |
17 ms |
29952 KB |
Output is correct |
8 |
Correct |
15 ms |
30464 KB |
Output is correct |
9 |
Correct |
17 ms |
30464 KB |
Output is correct |
10 |
Correct |
17 ms |
30208 KB |
Output is correct |
11 |
Correct |
22 ms |
30208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
31488 KB |
Output is correct |
2 |
Correct |
89 ms |
42408 KB |
Output is correct |
3 |
Correct |
208 ms |
59632 KB |
Output is correct |
4 |
Correct |
149 ms |
59888 KB |
Output is correct |
5 |
Correct |
167 ms |
59664 KB |
Output is correct |
6 |
Correct |
180 ms |
58096 KB |
Output is correct |
7 |
Correct |
202 ms |
57584 KB |
Output is correct |
8 |
Correct |
157 ms |
55536 KB |
Output is correct |
9 |
Correct |
142 ms |
59888 KB |
Output is correct |
10 |
Correct |
212 ms |
57840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
163 ms |
50928 KB |
Output is correct |
2 |
Correct |
207 ms |
56336 KB |
Output is correct |
3 |
Correct |
203 ms |
56304 KB |
Output is correct |
4 |
Correct |
205 ms |
55792 KB |
Output is correct |
5 |
Correct |
202 ms |
54512 KB |
Output is correct |
6 |
Correct |
205 ms |
57328 KB |
Output is correct |
7 |
Correct |
217 ms |
57328 KB |
Output is correct |
8 |
Correct |
227 ms |
60144 KB |
Output is correct |
9 |
Correct |
214 ms |
56048 KB |
Output is correct |
10 |
Correct |
221 ms |
57584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
29952 KB |
Output is correct |
2 |
Correct |
15 ms |
30464 KB |
Output is correct |
3 |
Correct |
14 ms |
30464 KB |
Output is correct |
4 |
Correct |
14 ms |
30464 KB |
Output is correct |
5 |
Correct |
14 ms |
30464 KB |
Output is correct |
6 |
Correct |
16 ms |
30208 KB |
Output is correct |
7 |
Correct |
16 ms |
30208 KB |
Output is correct |
8 |
Correct |
15 ms |
30208 KB |
Output is correct |
9 |
Correct |
17 ms |
30208 KB |
Output is correct |
10 |
Correct |
18 ms |
30464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
197 ms |
56304 KB |
Output is correct - 120000 bits used |
2 |
Correct |
208 ms |
56304 KB |
Output is correct - 122000 bits used |
3 |
Correct |
219 ms |
56304 KB |
Output is correct - 125000 bits used |
4 |
Correct |
209 ms |
56304 KB |
Output is correct - 125000 bits used |
5 |
Correct |
210 ms |
56304 KB |
Output is correct - 125000 bits used |
6 |
Correct |
208 ms |
56304 KB |
Output is correct - 125000 bits used |
7 |
Correct |
213 ms |
56560 KB |
Output is correct - 124828 bits used |
8 |
Correct |
204 ms |
56304 KB |
Output is correct - 124910 bits used |
9 |
Correct |
206 ms |
56304 KB |
Output is correct - 125000 bits used |
10 |
Correct |
188 ms |
59168 KB |
Output is correct - 125000 bits used |