#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "advisor.h"
using namespace std;
using namespace __gnu_pbds;
using Set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
void ComputeAdvice(int *C, int N, int K, int M) {
set<pair<int, int>> q;
int s[N], nx[N];
bool f[N] = {false};
fill(s, s+N, N);
int c[N];
for(int i = N-1;i >= 0;i--) {
nx[i] = s[C[i]];
s[C[i]] = i;
}
int sz = 0;
Set pbd;
vector<int> bad;
for(int i = 0;i < K;i++){
WriteAdvice(s[i] != N);
if(s[i] != N) {
sz++;
pbd.insert(i);
q.insert({s[i], i});
} else {
bad.push_back(i);
}
f[i] = true;
c[i] = i;
}
for(int i = 0;i < N;i++){
if(f[C[i]]) {
int ind = q.begin()->second;
q.erase(q.begin());
WriteAdvice(nx[i] != N);
if(nx[i] == N) {
sz--;
bad.push_back(ind);
pbd.erase(pbd.find(ind));
}
else {
q.insert({nx[i], ind});
}
continue;
}
if(!bad.empty()){
int ind = bad.back();
bad.pop_back();
WriteAdvice(nx[i] != N);
if(nx[i] != N) {
sz++;
pbd.insert(ind);
q.insert({nx[i], ind});
} else bad.push_back(ind);
f[c[ind]] = false;
f[C[i]] = true;
c[ind] = C[i];
continue;
}
int ind = q.rbegin()->second;
int L = log2(sz-1) + 1;
int pind = pbd.order_of_key(ind);
for(int b = 0;b < L;b++) WriteAdvice(1&(pind>>b));
WriteAdvice(nx[i] != N);
q.erase(prev(q.end()));
if(nx[i] == N) {
sz--;
pbd.erase(pbd.find(ind));
bad.emplace_back(ind);
}
else q.insert({nx[i], ind});
f[c[ind]] = false;
f[C[i]] = true;
c[ind] = C[i];
}
}
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "assistant.h"
using namespace std;
using namespace __gnu_pbds;
using Set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
void Assist(unsigned char *A, int N, int K, int R) {
int c[N], indo[N];
bool f[N] = {false};
int cur = 0, sz = 0;
Set pbd;
vector<pair<int, int>> bad;
for(int i = 0;i < K;i++){
f[i] = true;
c[i] = i;
indo[i] = i;
if(A[cur++]){
sz++;
pbd.insert(i);
} else bad.emplace_back(i, i);
}
for(int i = 0;i < N;i++){
int r = GetRequest();
if(f[r]) {
if(!A[cur++]){
sz--;
pbd.erase(pbd.find(indo[r]));
bad.emplace_back(r, indo[r]);
}
continue;
}
if(!bad.empty()){
PutBack(bad.back().first);
int ind = bad.back().second;
f[r] = true;
f[bad.back().first] = false;
indo[r] = ind;
c[ind] = r;
bad.pop_back();
if(A[cur++]) {
sz++;
pbd.insert(ind);
} else bad.emplace_back(r, ind);
continue;
}
int pind = 0, L = log2(sz-1)+1;
for(int b = 0;b < L;b++) {
if(A[cur]) pind |= 1 << b;
cur++;
}
int ind = *pbd.find_by_order(pind);
PutBack(c[ind]);
f[r] = true;
f[c[ind]] = false;
c[ind] = r;
indo[r] = ind;
if(!A[cur++]){
sz--;
pbd.erase(pbd.find(ind));
bad.emplace_back(r, ind);
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
508 KB |
Output is correct |
2 |
Correct |
1 ms |
520 KB |
Output is correct |
3 |
Correct |
2 ms |
768 KB |
Output is correct |
4 |
Correct |
3 ms |
788 KB |
Output is correct |
5 |
Correct |
3 ms |
828 KB |
Output is correct |
6 |
Correct |
5 ms |
968 KB |
Output is correct |
7 |
Correct |
4 ms |
952 KB |
Output is correct |
8 |
Correct |
3 ms |
948 KB |
Output is correct |
9 |
Correct |
5 ms |
976 KB |
Output is correct |
10 |
Correct |
6 ms |
1088 KB |
Output is correct |
11 |
Correct |
5 ms |
952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
1372 KB |
Output is correct |
2 |
Correct |
47 ms |
4812 KB |
Output is correct |
3 |
Correct |
97 ms |
11952 KB |
Output is correct |
4 |
Correct |
73 ms |
7680 KB |
Output is correct |
5 |
Correct |
89 ms |
8200 KB |
Output is correct |
6 |
Correct |
85 ms |
8372 KB |
Output is correct |
7 |
Correct |
83 ms |
9536 KB |
Output is correct |
8 |
Correct |
65 ms |
9576 KB |
Output is correct |
9 |
Correct |
92 ms |
8460 KB |
Output is correct |
10 |
Correct |
94 ms |
10392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
7392 KB |
Output is correct |
2 |
Correct |
84 ms |
8832 KB |
Output is correct |
3 |
Correct |
83 ms |
8868 KB |
Output is correct |
4 |
Correct |
86 ms |
8904 KB |
Output is correct |
5 |
Correct |
84 ms |
8684 KB |
Output is correct |
6 |
Correct |
83 ms |
10140 KB |
Output is correct |
7 |
Correct |
84 ms |
10076 KB |
Output is correct |
8 |
Correct |
71 ms |
10692 KB |
Output is correct |
9 |
Correct |
74 ms |
10484 KB |
Output is correct |
10 |
Correct |
86 ms |
10060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
920 KB |
Output is correct |
2 |
Correct |
3 ms |
908 KB |
Output is correct |
3 |
Incorrect |
1 ms |
660 KB |
Error - advice is too long |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
8716 KB |
Output is correct - 131760 bits used |
2 |
Correct |
84 ms |
9064 KB |
Output is correct - 122000 bits used |
3 |
Correct |
89 ms |
8960 KB |
Output is correct - 125000 bits used |
4 |
Correct |
93 ms |
8996 KB |
Output is correct - 125000 bits used |
5 |
Correct |
86 ms |
8948 KB |
Output is correct - 125000 bits used |
6 |
Correct |
83 ms |
8900 KB |
Output is correct - 125000 bits used |
7 |
Correct |
84 ms |
8940 KB |
Output is correct - 124828 bits used |
8 |
Correct |
84 ms |
8916 KB |
Output is correct - 124910 bits used |
9 |
Correct |
84 ms |
8876 KB |
Output is correct - 125000 bits used |
10 |
Correct |
71 ms |
8728 KB |
Output is correct - 139340 bits used |