#include "advisor.h"
#include <bits/stdc++.h>
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
static const int N = 1e5 + 5;
static int t[N];
static void update(int x, int k) {
for(int i = x + 1; i < N; i += i & -i)
t[i] += k;
}
static int query(int x, int ret = 0) {
for(int i = x + 1; i; i -= i & -i)
ret += t[i];
return ret;
}
static queue<int> col[N];
void ComputeAdvice(int *C, int n, int k, int M) {
for(int i = 0; i < n; i++) col[C[i]].emplace(i);
for(int i = 0; i < n; i++) col[i].emplace(1e9);
priority_queue<pii> Q;
for(int i = 0; i < k; i++) update(i, 1), Q.emplace(col[i].front(), i);
for(int i = 0; i < n; i++) {
col[C[i]].pop();
if(query(C[i]) - query(C[i] - 1) == 1)
for(int j = 0; j < 15; j++) WriteAdvice(0);
else {
pii now = Q.top(); Q.pop();
int idx = query(now.y);
for(int j = 0; j < 15; j++) WriteAdvice(idx >> j & 1);
Q.emplace(col[C[i]].front(), C[i]);
update(now.y, -1), update(C[i], 1);
}
}
}
#include "assistant.h"
#include <bits/stdc++.h>
using namespace std;
static const int N = 1e5 + 5;
static int t[N];
static void update(int x, int k) {
for(int i = x + 1; i < N; i += i & -i)
t[i] += k;
}
static int query(int x, int ret = 0) {
for(int i = x + 1; i; i -= i & -i)
ret += t[i];
return ret;
}
void Assist(unsigned char *A, int n, int k, int R) {
for(int i = 0; i < k; i++) update(i, 1);
for(int i = 0; i < n; i++) {
int now = GetRequest();
if(query(now) - query(now - 1) == 1) continue;
int idx = 0;
for(int j = 15 * i; j < 15 * (i + 1); j++)
if(A[j] == 1) idx += (1 << (j - 15 * i));
int l = 0, r = n - 1;
while(l < r) {
int mid = (l + r) >> 1;
if(query(mid) >= idx) r = mid;
else l = mid + 1;
}
PutBack(r);
update(r, -1), update(now, 1);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
135416 KB |
Output is correct |
2 |
Incorrect |
53 ms |
135408 KB |
Output isn't correct - not an optimal way |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
98 ms |
136688 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
431 ms |
146112 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
55 ms |
135408 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
532 ms |
148400 KB |
Output isn't correct - not an optimal way |
2 |
Incorrect |
568 ms |
148368 KB |
Output isn't correct - not an optimal way |
3 |
Incorrect |
506 ms |
148608 KB |
Output isn't correct - not an optimal way |
4 |
Incorrect |
500 ms |
148584 KB |
Output isn't correct - not an optimal way |
5 |
Incorrect |
503 ms |
148328 KB |
Output isn't correct - not an optimal way |
6 |
Incorrect |
503 ms |
148320 KB |
Output isn't correct - not an optimal way |
7 |
Incorrect |
528 ms |
148328 KB |
Output isn't correct - not an optimal way |
8 |
Incorrect |
512 ms |
148296 KB |
Output isn't correct - not an optimal way |
9 |
Incorrect |
494 ms |
148576 KB |
Output isn't correct - not an optimal way |
10 |
Correct |
546 ms |
148592 KB |
Output is partially correct - 1500000 bits used |