#include "advisor.h"
#include <bits/stdc++.h>
#include <bits/extc++.h>
#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define ef(a) emplace_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define tomax(a, b) ((a) = max((a), (b)))
#define tomin(a, b) ((a) = min((a), (b)))
#define topos(a) ((a) = (((a) % MOD + MOD) % MOD))
#define uni(a) a.resize(unique(iter(a)) - a.begin())
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
if(pvaspace) b << " "; pvaspace=true;\
b << pva;\
}\
b << "\n";}
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;
const ll MOD = 1000000007;
const ll MAX = 2147483647;
template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
return o << '(' << p.F << ',' << p.S << ')';
}
void ComputeAdvice(int *C, int n, int k, int M){
vector<int> ans(k + n);
vector<int> lst(n, -1);
vector<queue<int>> pos(n);
for(int i = 0; i < n; i++){
pos[C[i]].push(k + i);
}
for(int i = 0; i < n; i++) pos[i].push(k + n);
set<pii> st;
for(int i = 0; i < k; i++){
lst[i] = i;
st.insert(mp(pos[i].front(), i));
}
for(int i = 0; i < n; i++){
int c = C[i];
if(lst[c] != -1){
lst[c] = k + i;
st.erase(mp(pos[c].front(), c));
pos[c].pop();
st.insert(mp(pos[c].front(), c));
continue;
}
int r = st.rbegin()->S;
st.erase(prev(st.end()));
ans[lst[r]] = 1;
lst[r] = -1;
lst[c] = k + i;
pos[c].pop();
st.insert(mp(pos[c].front(), c));
}
for(int i : ans) WriteAdvice(i);
}
#include "assistant.h"
#include <bits/stdc++.h>
#include <bits/extc++.h>
#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define ef(a) emplace_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define tomax(a, b) ((a) = max((a), (b)))
#define tomin(a, b) ((a) = min((a), (b)))
#define topos(a) ((a) = (((a) % MOD + MOD) % MOD))
#define uni(a) a.resize(unique(iter(a)) - a.begin())
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
if(pvaspace) b << " "; pvaspace=true;\
b << pva;\
}\
b << "\n";}
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;
const ll MOD = 1000000007;
const ll MAX = 2147483647;
template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
return o << '(' << p.F << ',' << p.S << ')';
}
void Assist(unsigned char *A, int n, int k, int R) {
set<int> q;
vector<bool> ok(n);
for(int i = 0; i < k; i++){
if(A[i]) q.insert(i);
ok[i] = true;
}
for(int i = k; i < k + n; i++){
int c = GetRequest();
assert(q.find(c) == q.end());
q.erase(c);
if(!ok[c]){
int r = *q.begin();
q.erase(r);
PutBack(r);
ok[r] = false;
ok[c] = true;
}
if(A[i]) q.insert(c);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
484 KB |
Output is correct |
2 |
Correct |
1 ms |
612 KB |
Output is correct |
3 |
Correct |
3 ms |
1256 KB |
Output is correct |
4 |
Correct |
4 ms |
2564 KB |
Output is correct |
5 |
Correct |
7 ms |
3992 KB |
Output is correct |
6 |
Correct |
7 ms |
3984 KB |
Output is correct |
7 |
Correct |
9 ms |
4128 KB |
Output is correct |
8 |
Correct |
8 ms |
3988 KB |
Output is correct |
9 |
Correct |
8 ms |
4124 KB |
Output is correct |
10 |
Correct |
9 ms |
4256 KB |
Output is correct |
11 |
Correct |
9 ms |
4248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
7768 KB |
Output is correct |
2 |
Correct |
92 ms |
36172 KB |
Output is correct |
3 |
Correct |
220 ms |
72656 KB |
Output is correct |
4 |
Correct |
186 ms |
70524 KB |
Output is correct |
5 |
Correct |
182 ms |
70436 KB |
Output is correct |
6 |
Correct |
197 ms |
71072 KB |
Output is correct |
7 |
Correct |
226 ms |
71856 KB |
Output is correct |
8 |
Correct |
159 ms |
61284 KB |
Output is correct |
9 |
Correct |
142 ms |
69208 KB |
Output is correct |
10 |
Correct |
231 ms |
72436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
181 ms |
57976 KB |
Output is correct |
2 |
Correct |
209 ms |
72104 KB |
Output is correct |
3 |
Correct |
225 ms |
72272 KB |
Output is correct |
4 |
Correct |
216 ms |
72188 KB |
Output is correct |
5 |
Correct |
214 ms |
71412 KB |
Output is correct |
6 |
Correct |
220 ms |
72240 KB |
Output is correct |
7 |
Correct |
216 ms |
72152 KB |
Output is correct |
8 |
Correct |
213 ms |
71780 KB |
Output is correct |
9 |
Correct |
201 ms |
72644 KB |
Output is correct |
10 |
Correct |
225 ms |
72440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
3312 KB |
Output is correct |
2 |
Correct |
9 ms |
4120 KB |
Output is correct |
3 |
Correct |
7 ms |
3988 KB |
Output is correct |
4 |
Correct |
7 ms |
4000 KB |
Output is correct |
5 |
Correct |
9 ms |
3988 KB |
Output is correct |
6 |
Correct |
7 ms |
3992 KB |
Output is correct |
7 |
Correct |
8 ms |
4120 KB |
Output is correct |
8 |
Correct |
8 ms |
4116 KB |
Output is correct |
9 |
Correct |
8 ms |
4240 KB |
Output is correct |
10 |
Correct |
10 ms |
4228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
257 ms |
71900 KB |
Output is correct - 120000 bits used |
2 |
Correct |
223 ms |
72204 KB |
Output is correct - 122000 bits used |
3 |
Correct |
228 ms |
72172 KB |
Output is correct - 125000 bits used |
4 |
Correct |
211 ms |
72128 KB |
Output is correct - 125000 bits used |
5 |
Correct |
252 ms |
72204 KB |
Output is correct - 125000 bits used |
6 |
Correct |
226 ms |
72236 KB |
Output is correct - 125000 bits used |
7 |
Correct |
219 ms |
72072 KB |
Output is correct - 124828 bits used |
8 |
Correct |
223 ms |
72216 KB |
Output is correct - 124910 bits used |
9 |
Correct |
212 ms |
72156 KB |
Output is correct - 125000 bits used |
10 |
Correct |
205 ms |
71888 KB |
Output is correct - 125000 bits used |