#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 int col[N];
void ComputeAdvice(int *C, int n, int k, int M) {
for(int i = 0; i < n; i++) col[i] = lower_bound(C, C + n, i) - C;
priority_queue<pii> Q;
for(int i = 0; i < k; i++) update(i, 1), Q.emplace(col[i], i);
for(int i = 0; i < n; i++) {
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();
col[now.y] = lower_bound(C + i + 1, C + n, now.y) - C;
int idx = query(now.y);
for(int j = 0; j < 15; j++) WriteAdvice(idx >> j & 1);
col[C[i]] = lower_bound(C + i + 1, C + n, C[i]) - C;
Q.emplace(col[C[i]], 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);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
996 KB |
Output is correct |
2 |
Incorrect |
2 ms |
1000 KB |
Output isn't correct - not an optimal way |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
41 ms |
2212 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
374 ms |
11192 KB |
Output isn't correct - not an optimal way |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
916 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
457 ms |
13728 KB |
Output isn't correct - not an optimal way |
2 |
Incorrect |
454 ms |
13712 KB |
Output isn't correct - not an optimal way |
3 |
Incorrect |
466 ms |
13920 KB |
Output isn't correct - not an optimal way |
4 |
Incorrect |
443 ms |
13664 KB |
Output isn't correct - not an optimal way |
5 |
Incorrect |
435 ms |
13704 KB |
Output isn't correct - not an optimal way |
6 |
Incorrect |
440 ms |
13656 KB |
Output isn't correct - not an optimal way |
7 |
Incorrect |
422 ms |
13920 KB |
Output isn't correct - not an optimal way |
8 |
Incorrect |
428 ms |
13664 KB |
Output isn't correct - not an optimal way |
9 |
Incorrect |
429 ms |
13776 KB |
Output isn't correct - not an optimal way |
10 |
Incorrect |
423 ms |
13656 KB |
Output isn't correct - not an optimal way |