#include <bits/stdc++.h>
#include "advisor.h"
#define pb emplace_back
#define pii pair<int,int>
#define ff first
#define ss second
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }
const int MAXN = 100000;
int P;
vector <int> nxt[MAXN+1];
vector <int> cur;
vector <int> pos;
vector <int> id;
class Seg {
private:
pii arr[MAXN*4+5];
void pull(int now) {
arr[now] = max(arr[now*2], arr[now*2+1]);
}
public:
void build(int now, int l, int r) {
if (l == r) {
arr[now] = pii(*nxt[l].begin(), l);
return;
}
int mid = l + r >> 1;
build(now*2 , l, mid);
build(now*2+1,mid+1,r);
pull(now);
return;
}
void mdy(int p, int id, int now, int l, int r) {
if (l == p && r == p) {
arr[now] = pii(nxt[id][cur[id]], l);
return;
} else if (l > p || r < p) return;
int mid = l + r >> 1;
mdy(p, id, now*2 , l, mid);
mdy(p, id, now*2+1,mid+1,r);
pull(now);
return;
}
pii qry() {
return arr[1];
}
} seg;
void init(int *C, int N, int K, int M) {
P = __lg(N)+1;
id.resize(N);
cur.resize(N);
pos.resize(K);
for (int i = 0; i < N; i++) nxt[C[i]].pb(i);
for (int i = 0; i < N; i++) nxt[i].pb(N);
for (int i = 0; i < K; i++) pos[i] = i, id[i] = i;
for (int i = K; i < N; i++) id[i] = -1;
}
void Write(int num) {
for (int i = 0; i < P; i++) {
if ((1<<i) & num)
WriteAdvice(1);
else
WriteAdvice(0);
}
}
void ComputeAdvice(int *C, int N, int K, int M) {
init(C, N, K, M);
seg.build(1, 0, K-1);
for (int i = 0; i < N; i++) {
cur[C[i]]++;
if (id[C[i]] != -1) {
seg.mdy(id[C[i]], C[i], 1, 0, K-1);
} else {
auto [_t, p] = seg.qry();
Write(pos[p]);
id[pos[p]] = -1;
id[C[i]] = p;
pos[p] = C[i];
seg.mdy(p, C[i], 1, 0, K-1);
}
}
}
#include <bits/stdc++.h>
#include "assistant.h"
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }
const int MAXN = 100000;
int P;
vector <int> id;
void init(int N, int K, int M) {
P = __lg(N)+1;
id.resize(N);
for (int i = 0; i < K; i++) id[i] = i;
for (int i = K; i < N; i++) id[i] = -1;
}
int fnd(unsigned char *A, int a) {
int st = a * P, num = 0;
for (int i = st; i < st + P; i++) {
if ((int)A[i]) num += (1<<(i-st));
}
return num;
}
void Assist(unsigned char *A, int N, int K, int R) {
init(N, K, R);
int now = 0;
for (int i = 0; i < N; i++) {
int req = GetRequest();
if (id[req] == -1) {
int num = fnd(A, now++);
PutBack(num);
id[req] = id[num];
id[num] = -1;
}
}
}
Compilation message
advisor.cpp: In member function 'void Seg::build(int, int, int)':
advisor.cpp:32:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
32 | int mid = l + r >> 1;
| ~~^~~
advisor.cpp: In member function 'void Seg::mdy(int, int, int, int, int)':
advisor.cpp:43:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
43 | int mid = l + r >> 1;
| ~~^~~
advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:82:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
82 | auto [_t, p] = seg.qry();
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3288 KB |
Output is correct |
2 |
Correct |
3 ms |
3228 KB |
Output is correct |
3 |
Correct |
3 ms |
3300 KB |
Output is correct |
4 |
Correct |
9 ms |
3572 KB |
Output is correct |
5 |
Correct |
20 ms |
3860 KB |
Output is correct |
6 |
Correct |
19 ms |
3688 KB |
Output is correct |
7 |
Correct |
8 ms |
3464 KB |
Output is correct |
8 |
Correct |
18 ms |
3768 KB |
Output is correct |
9 |
Correct |
16 ms |
3720 KB |
Output is correct |
10 |
Correct |
12 ms |
3548 KB |
Output is correct |
11 |
Correct |
13 ms |
3720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
4408 KB |
Output is correct |
2 |
Correct |
120 ms |
8712 KB |
Output is correct |
3 |
Correct |
325 ms |
16868 KB |
Output is correct |
4 |
Correct |
447 ms |
19524 KB |
Output is correct |
5 |
Correct |
428 ms |
18892 KB |
Output is correct |
6 |
Correct |
373 ms |
17316 KB |
Output is correct |
7 |
Correct |
298 ms |
15784 KB |
Output is correct |
8 |
Correct |
316 ms |
15448 KB |
Output is correct |
9 |
Correct |
412 ms |
19484 KB |
Output is correct |
10 |
Correct |
278 ms |
14688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
227 ms |
12968 KB |
Output is correct |
2 |
Correct |
290 ms |
15020 KB |
Output is correct |
3 |
Correct |
282 ms |
14984 KB |
Output is correct |
4 |
Correct |
263 ms |
14320 KB |
Output is correct |
5 |
Correct |
224 ms |
13552 KB |
Output is correct |
6 |
Correct |
284 ms |
15276 KB |
Output is correct |
7 |
Correct |
270 ms |
14880 KB |
Output is correct |
8 |
Correct |
382 ms |
17820 KB |
Output is correct |
9 |
Correct |
201 ms |
13112 KB |
Output is correct |
10 |
Correct |
279 ms |
15104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
3528 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
333 ms |
15388 KB |
Output is partially correct - 875347 bits used |
2 |
Correct |
295 ms |
15288 KB |
Output is partially correct - 841041 bits used |
3 |
Correct |
294 ms |
15232 KB |
Output is partially correct - 807466 bits used |
4 |
Correct |
324 ms |
15024 KB |
Output is partially correct - 806939 bits used |
5 |
Correct |
294 ms |
15028 KB |
Output is partially correct - 805358 bits used |
6 |
Correct |
301 ms |
15136 KB |
Output is partially correct - 807109 bits used |
7 |
Correct |
284 ms |
15248 KB |
Output is partially correct - 805902 bits used |
8 |
Correct |
285 ms |
15064 KB |
Output is partially correct - 808452 bits used |
9 |
Correct |
295 ms |
15248 KB |
Output is partially correct - 807874 bits used |
10 |
Correct |
390 ms |
17688 KB |
Output is partially correct - 1266636 bits used |