#include "advisor.h"
#include <bits/stdc++.h>
#include <bits/extc++.h>
#define IO_OP ios::sync_with_stdio(0), cin.tie(0)
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int INF = 1e9 + 7;
void ComputeAdvice(int *a, int n, int k, int m) {
vi next_occ(n, INF), nxt(n);
for(int i = n - 1; i >= 0; i--) {
nxt[i] = next_occ[a[i]];
next_occ[a[i]] = i;
}
set<pi> s;
ordered_set<int> tt;
for(int i = 0; i < k; i++) {
s.insert({next_occ[i], i});
tt.insert(i);
}
for(int i = 0; i < n; i++) {
if(tt.find(a[i]) != tt.end()) {
s.erase({i, a[i]});
s.insert({nxt[i], a[i]});
} else {
auto[pos, val] = *s.rbegin();
s.erase({pos, val});
int rk = tt.order_of_key(val);
for(int j = 0; j < __lg(k - 1) + 1; j++)
WriteAdvice(rk >> j & 1);
tt.erase(val);
s.insert({nxt[i], a[i]});
tt.insert(a[i]);
}
}
}
// WriteAdvice
#include "assistant.h"
#include <bits/stdc++.h>
#include <bits/extc++.h>
#define IO_OP ios::sync_with_stdio(0), cin.tie(0)
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int INF = 1e9 + 7;
void Assist(unsigned char *a, int n, int k, int r) {
ordered_set<int> tt;
for(int i = 0; i < k; i++) {
tt.insert(i);
}
int sz = 0;
for(int i = 0; i < n; i++) {
int req = GetRequest();
if(tt.find(req) != tt.end()) {
} else {
int rk = 0;
for(int j = 0; j < __lg(k - 1) + 1; j++)
rk += int(a[sz++]) << j;
int val = *tt.find_by_order(rk);
PutBack(val);
tt.erase(val);
tt.insert(req);
}
}
}
Compilation message
advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:42:17: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
42 | auto[pos, val] = *s.rbegin();
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
508 KB |
Output is correct |
2 |
Correct |
1 ms |
516 KB |
Output is correct |
3 |
Correct |
2 ms |
764 KB |
Output is correct |
4 |
Correct |
4 ms |
660 KB |
Output is correct |
5 |
Correct |
3 ms |
676 KB |
Output is correct |
6 |
Correct |
10 ms |
1008 KB |
Output is correct |
7 |
Correct |
6 ms |
956 KB |
Output is correct |
8 |
Correct |
15 ms |
1124 KB |
Output is correct |
9 |
Correct |
13 ms |
1132 KB |
Output is correct |
10 |
Correct |
11 ms |
1120 KB |
Output is correct |
11 |
Correct |
10 ms |
1120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
1408 KB |
Output is correct |
2 |
Correct |
99 ms |
3752 KB |
Output is correct |
3 |
Correct |
367 ms |
13160 KB |
Output is correct |
4 |
Correct |
173 ms |
7240 KB |
Output is correct |
5 |
Correct |
256 ms |
9236 KB |
Output is correct |
6 |
Correct |
288 ms |
10052 KB |
Output is correct |
7 |
Correct |
315 ms |
11148 KB |
Output is correct |
8 |
Correct |
316 ms |
12048 KB |
Output is correct |
9 |
Correct |
124 ms |
5868 KB |
Output is correct |
10 |
Correct |
278 ms |
11848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
225 ms |
8268 KB |
Output is correct |
2 |
Correct |
285 ms |
10368 KB |
Output is correct |
3 |
Correct |
281 ms |
10348 KB |
Output is correct |
4 |
Correct |
276 ms |
10000 KB |
Output is correct |
5 |
Correct |
243 ms |
8256 KB |
Output is correct |
6 |
Correct |
281 ms |
10384 KB |
Output is correct |
7 |
Correct |
282 ms |
10044 KB |
Output is correct |
8 |
Correct |
375 ms |
12860 KB |
Output is correct |
9 |
Correct |
193 ms |
8396 KB |
Output is correct |
10 |
Correct |
287 ms |
10444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
768 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
337 ms |
9956 KB |
Output is partially correct - 772365 bits used |
2 |
Correct |
287 ms |
10088 KB |
Output is partially correct - 742095 bits used |
3 |
Correct |
346 ms |
10432 KB |
Output is partially correct - 712470 bits used |
4 |
Correct |
279 ms |
10396 KB |
Output is partially correct - 712005 bits used |
5 |
Correct |
293 ms |
10348 KB |
Output is partially correct - 710610 bits used |
6 |
Correct |
313 ms |
10268 KB |
Output is partially correct - 712155 bits used |
7 |
Correct |
278 ms |
10304 KB |
Output is partially correct - 711090 bits used |
8 |
Correct |
294 ms |
10520 KB |
Output is partially correct - 713340 bits used |
9 |
Correct |
274 ms |
10400 KB |
Output is partially correct - 712830 bits used |
10 |
Correct |
354 ms |
12960 KB |
Output is partially correct - 1117620 bits used |