#include "advisor.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
#include <queue>
#include <set>
typedef long long llong;
const int MAXN = 100000 + 10;
const int MAXLOG = 17;
const int INF = 1e9;
int n, k;
struct BIT
{
int tree[MAXN];
void update(int idx, int val)
{
for (int pos = idx ; pos <= n ; pos += pos & (-pos))
{
tree[pos] += val;
}
}
int query(int idx)
{
int res = 0;
for (int pos = idx ; pos > 0 ; pos -= pos & (-pos))
{
res += tree[pos];
}
return res;
}
int findKth(int k)
{
int pos = 0;
for (int log = MAXLOG - 1 ; log >= 0 ; --log)
{
if (pos + (1 << log) <= n && tree[pos + (1 << log)] < k)
{
pos += (1 << log);
k -= tree[pos];
}
}
return pos + 1;
}
};
int logK;
int c[MAXN];
bool in[MAXN];
int last[MAXN];
int last2[MAXN];
int next[MAXN];
std::set <std::pair <int,int>> pq;
BIT tree;
void ComputeAdvice(int *C, int N, int K, int M)
{
n = N;
k = K;
while ((1 << logK + 1) <= k) logK++;
for (int i = 1 ; i <= n ; ++i)
{
last[i] = n + 1;
}
for (int i = n ; i >= 1 ; --i)
{
c[i] = C[i - 1] + 1;
next[i] = last[c[i]];
last[c[i]] = i;
}
for (int i = 1 ; i <= k ; ++i)
{
in[i] = true;
last2[i] = last[i];
pq.insert({last[i], i});
tree.update(i, 1);
}
for (int i = 1 ; i <= n ; ++i)
{
if (in[c[i]])
{
pq.erase(pq.find({last2[c[i]], c[i]}));
last2[c[i]] = next[i];
pq.insert({next[i], c[i]});
continue;
}
auto [val, col] = *(pq.rbegin());
pq.erase(pq.find(*pq.rbegin()));
int curr = tree.query(col);
for (int bit = logK ; bit >= 0 ; --bit)
{
WriteAdvice((curr & (1 << bit)) > 0);
}
tree.update(col, -1);
tree.update(c[i], 1);
in[col] = false;
in[c[i]] = true;
pq.insert({next[i], c[i]});
last2[c[i]] = next[i];
}
}
#include "assistant.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
#include <queue>
typedef long long llong;
const int MAXN = 100000 + 10;
const int MAXLOG = 17;
const int INF = 1e9;
int N, K;
struct BIT2
{
int tree[MAXN];
void update(int idx, int val)
{
for (int pos = idx ; pos <= N ; pos += pos & (-pos))
{
tree[pos] += val;
}
}
int query(int idx)
{
int res = 0;
for (int pos = idx ; pos > 0 ; pos -= pos & (-pos))
{
res += tree[pos];
}
return res;
}
int findKth(int k)
{
int pos = 0;
for (int log = MAXLOG - 1 ; log >= 0 ; --log)
{
if (pos + (1 << log) <= N && tree[pos + (1 << log)] < k)
{
pos += (1 << log);
k -= tree[pos];
}
}
return pos + 1;
}
};
int logK2;
bool in2[MAXN];
BIT2 tree2;
void Assist(unsigned char *A, int _N, int _K, int R)
{
N = _N; K = _K;
while ((1 << logK2 + 1) <= K) logK2++;
for (int i = 1 ; i <= K ; ++i)
{
in2[i] = true;
tree2.update(i, 1);
}
int ptr = 0;
for (int i = 1 ; i <= N ; ++i)
{
int curr = GetRequest() + 1;
if (in2[curr])
{
continue;
}
int toRemove = 0;
for (int j = 0 ; j <= logK2 ; ++j)
{
toRemove *= 2;
assert(A[ptr] == 0 || A[ptr] == 1);
toRemove += A[ptr++];
}
toRemove = tree2.findKth(toRemove);
PutBack(toRemove - 1);
tree2.update(toRemove, -1);
tree2.update(curr, 1);
in2[toRemove] = false;
in2[curr] = true;
}
}
Compilation message
advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:67:23: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
67 | while ((1 << logK + 1) <= k) logK++;
| ~~~~~^~~
assistant.cpp: In function 'void Assist(unsigned char*, int, int, int)':
assistant.cpp:60:24: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
60 | while ((1 << logK2 + 1) <= K) logK2++;
| ~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
512 KB |
Output is correct |
2 |
Correct |
0 ms |
524 KB |
Output is correct |
3 |
Correct |
1 ms |
640 KB |
Output is correct |
4 |
Correct |
3 ms |
796 KB |
Output is correct |
5 |
Correct |
4 ms |
932 KB |
Output is correct |
6 |
Correct |
7 ms |
976 KB |
Output is correct |
7 |
Correct |
3 ms |
924 KB |
Output is correct |
8 |
Correct |
10 ms |
1180 KB |
Output is correct |
9 |
Correct |
9 ms |
1192 KB |
Output is correct |
10 |
Correct |
6 ms |
1088 KB |
Output is correct |
11 |
Correct |
9 ms |
1072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
1412 KB |
Output is correct |
2 |
Correct |
77 ms |
4548 KB |
Output is correct |
3 |
Correct |
208 ms |
12372 KB |
Output is correct |
4 |
Correct |
140 ms |
8596 KB |
Output is correct |
5 |
Correct |
194 ms |
10880 KB |
Output is correct |
6 |
Correct |
189 ms |
10976 KB |
Output is correct |
7 |
Correct |
183 ms |
10772 KB |
Output is correct |
8 |
Correct |
186 ms |
11056 KB |
Output is correct |
9 |
Correct |
104 ms |
7272 KB |
Output is correct |
10 |
Correct |
168 ms |
10432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
141 ms |
8508 KB |
Output is correct |
2 |
Correct |
189 ms |
10552 KB |
Output is correct |
3 |
Correct |
175 ms |
10612 KB |
Output is correct |
4 |
Correct |
157 ms |
10044 KB |
Output is correct |
5 |
Correct |
126 ms |
8820 KB |
Output is correct |
6 |
Correct |
164 ms |
10452 KB |
Output is correct |
7 |
Correct |
157 ms |
10304 KB |
Output is correct |
8 |
Correct |
217 ms |
13008 KB |
Output is correct |
9 |
Correct |
106 ms |
8656 KB |
Output is correct |
10 |
Correct |
162 ms |
10496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
768 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
169 ms |
10772 KB |
Output is partially correct - 772365 bits used |
2 |
Correct |
165 ms |
10616 KB |
Output is partially correct - 742095 bits used |
3 |
Correct |
189 ms |
10524 KB |
Output is partially correct - 712470 bits used |
4 |
Correct |
160 ms |
10508 KB |
Output is partially correct - 712005 bits used |
5 |
Correct |
161 ms |
10416 KB |
Output is partially correct - 710610 bits used |
6 |
Correct |
201 ms |
10628 KB |
Output is partially correct - 712155 bits used |
7 |
Correct |
165 ms |
10532 KB |
Output is partially correct - 711090 bits used |
8 |
Correct |
161 ms |
10544 KB |
Output is partially correct - 713340 bits used |
9 |
Correct |
165 ms |
10440 KB |
Output is partially correct - 712830 bits used |
10 |
Correct |
217 ms |
13252 KB |
Output is partially correct - 1117620 bits used |