#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;
set <int> appr;
class Seg {
private:
pii arr[MAXN*4+5];
int mmn[MAXN*4+5];
void pull(int now) {
arr[now] = max(arr[now*2], arr[now*2+1]);
mmn[now] = min(mmn[now*2], mmn[now*2+1]);
}
public:
void build(int now, int l, int r) {
if (l == r) {
arr[now] = pii(*nxt[l].begin(), l);
mmn[now] = *nxt[l].begin();
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);
mmn[now] = nxt[id][cur[id]];
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];
}
int mmin() {
return mmn[1];
}
} seg;
void init(int *C, int N, int K, int M) {
P = __lg(K)+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;
appr.clear();
}
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);
int stp = N;
for (int i = N-1; i >= 0; i--) {
if (appr.count(C[i])) {
stp = i;
break;
}
appr.insert(C[i]);
}
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 {
if (seg.mmin() == N && i > stp) break;
auto [_t, p] = seg.qry();
Write(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;
vector <int> pos;
void init(int N, int K, int M) {
P = __lg(K)+1;
id.resize(N);
pos.resize(K);
for (int i = 0; i < K; i++) id[i] = i, pos[i] = i;
for (int i = K; i < N; i++) id[i] = -1;
}
int fnd(unsigned char *A, int a, int R) {
int st = a * P, num = 0;
if (st > R) return 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++, R);
PutBack(pos[num]);
id[req] = id[pos[num]];
id[pos[num]] = -1;
pos[num] = req;
}
}
}
Compilation message
advisor.cpp: In member function 'void Seg::build(int, int, int)':
advisor.cpp:36:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
36 | int mid = l + r >> 1;
| ~~^~~
advisor.cpp: In member function 'void Seg::mdy(int, int, int, int, int)':
advisor.cpp:48:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
48 | int mid = l + r >> 1;
| ~~^~~
advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:100:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
100 | auto [_t, p] = seg.qry();
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
6372 KB |
Output is correct |
2 |
Correct |
5 ms |
6372 KB |
Output is correct |
3 |
Correct |
7 ms |
6372 KB |
Output is correct |
4 |
Correct |
8 ms |
6404 KB |
Output is correct |
5 |
Correct |
8 ms |
6536 KB |
Output is correct |
6 |
Correct |
16 ms |
6712 KB |
Output is correct |
7 |
Correct |
8 ms |
6692 KB |
Output is correct |
8 |
Correct |
19 ms |
6988 KB |
Output is correct |
9 |
Correct |
17 ms |
6864 KB |
Output is correct |
10 |
Correct |
12 ms |
6756 KB |
Output is correct |
11 |
Correct |
14 ms |
6704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
7172 KB |
Output is correct |
2 |
Correct |
108 ms |
11204 KB |
Output is correct |
3 |
Correct |
363 ms |
23004 KB |
Output is correct |
4 |
Correct |
212 ms |
16424 KB |
Output is correct |
5 |
Correct |
291 ms |
18292 KB |
Output is correct |
6 |
Correct |
323 ms |
18400 KB |
Output is correct |
7 |
Correct |
287 ms |
17648 KB |
Output is correct |
8 |
Correct |
337 ms |
21392 KB |
Output is correct |
9 |
Correct |
168 ms |
15452 KB |
Output is correct |
10 |
Correct |
262 ms |
17140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
230 ms |
15196 KB |
Output is correct |
2 |
Correct |
269 ms |
17384 KB |
Output is correct |
3 |
Correct |
278 ms |
17692 KB |
Output is correct |
4 |
Correct |
297 ms |
17012 KB |
Output is correct |
5 |
Correct |
219 ms |
16044 KB |
Output is correct |
6 |
Correct |
272 ms |
17364 KB |
Output is correct |
7 |
Correct |
278 ms |
17332 KB |
Output is correct |
8 |
Correct |
415 ms |
24592 KB |
Output is correct |
9 |
Correct |
194 ms |
16884 KB |
Output is correct |
10 |
Correct |
286 ms |
17700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
6660 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
284 ms |
17876 KB |
Output is partially correct - 772365 bits used |
2 |
Correct |
277 ms |
17592 KB |
Output is partially correct - 742095 bits used |
3 |
Correct |
275 ms |
17624 KB |
Output is partially correct - 712470 bits used |
4 |
Correct |
272 ms |
17720 KB |
Output is partially correct - 711990 bits used |
5 |
Correct |
275 ms |
17360 KB |
Output is partially correct - 710595 bits used |
6 |
Correct |
270 ms |
17344 KB |
Output is partially correct - 712155 bits used |
7 |
Correct |
276 ms |
17360 KB |
Output is partially correct - 711090 bits used |
8 |
Correct |
286 ms |
17608 KB |
Output is partially correct - 713340 bits used |
9 |
Correct |
270 ms |
17620 KB |
Output is partially correct - 712800 bits used |
10 |
Correct |
407 ms |
24320 KB |
Output is partially correct - 1117575 bits used |