#include "advisor.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 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 next[MAXN];
std::priority_queue <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) <= n) 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;
pq.push({last[i], i});
tree.update(i, 1);
}
for (int i = 1 ; i <= n ; ++i)
{
if (in[c[i]])
{
continue;
}
auto [val, col] = pq.top();
pq.pop();
assert(val >= pq.top().first);
int curr = tree.query(col);
for (int bit = logK ; bit >= 0 ; --bit)
{
WriteAdvice((col & (1 << bit)) > 0);
}
tree.update(col, -1);
tree.update(c[i], 1);
in[col] = false;
in[c[i]] = true;
pq.push({next[i], c[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) <= N) logK2++;
for (int i = 1 ; i <= K ; ++i)
{
assert(!in2[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:65:23: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
65 | while ((1 << logK + 1) <= n) logK++;
| ~~~~~^~~
advisor.cpp:97:13: warning: unused variable 'curr' [-Wunused-variable]
97 | int curr = tree.query(col);
| ^~~~
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) <= N) logK2++;
| ~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
512 KB |
Output is correct |
2 |
Incorrect |
1 ms |
520 KB |
Output isn't correct - not an optimal way |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
17 ms |
1664 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
159 ms |
9240 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
640 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
200 ms |
11792 KB |
Output isn't correct - not an optimal way |
2 |
Incorrect |
204 ms |
11544 KB |
Output isn't correct - not an optimal way |
3 |
Incorrect |
202 ms |
11104 KB |
Output isn't correct - not an optimal way |
4 |
Incorrect |
177 ms |
11072 KB |
Output isn't correct - not an optimal way |
5 |
Incorrect |
178 ms |
11056 KB |
Output isn't correct - not an optimal way |
6 |
Incorrect |
181 ms |
11252 KB |
Output isn't correct - not an optimal way |
7 |
Incorrect |
176 ms |
11020 KB |
Output isn't correct - not an optimal way |
8 |
Incorrect |
181 ms |
11128 KB |
Output isn't correct - not an optimal way |
9 |
Incorrect |
180 ms |
11240 KB |
Output isn't correct - not an optimal way |
10 |
Correct |
224 ms |
12600 KB |
Output is partially correct - 1266636 bits used |