#include "advisor.h"
#include <bits/stdc++.h>
using namespace std;
int get_dig(int k){
int ret = 1;
while((1<<ret) < k + 1){
ret++;
}
return ret;
}
struct BIT{
vector<int> bit;
int n;
BIT(int size){
n = size+5;
bit.assign(n,0);
}
void upd(int pos,int val){
for(++pos;pos < n;pos += pos & -pos){
bit[pos] += val;
}
}
int get(int pos){
int ret = 0;
for(++pos;pos > 0;pos -= pos & -pos){
ret += bit[pos];
}
return ret;
}
int get(int l,int r){
return get(r) - get(l-1);
}
};
void write(int x,int dig){
for(int i = dig-1;i>=0;i--){
if((1<<i) <= x){
WriteAdvice(1);
//cout << 1;
x -= (1<<i);
}
else{
WriteAdvice(0);
//cout <<0;
}
}
//cout << endl;
}
void ComputeAdvice(int *c, int n, int k, int m){
int dig = get_dig(k);
vector<int> occ[n];
for(int i = n-1;i>=0;i--){
occ[i].push_back(n);
}
for(int i = n-1;i>=0;i--){
occ[c[i]].push_back(i);
}
set<pair<int,int>> s;
BIT bt(n);
for(int i = 0;i<k;i++){
bt.upd(i,1);
s.insert({occ[i].back(),i});
}
for(int i = 0;i<n;i++){
if(bt.get(c[i],c[i]) == 1){
write(0,dig);
s.erase({occ[c[i]].back(),c[i]});
}
else{
//cout << s.rbegin()->second << endl;
write(bt.get(0,s.rbegin()->second),dig);
bt.upd(s.rbegin()->second,-1);
bt.upd(c[i],1);
s.erase(*s.rbegin());
}
occ[c[i]].pop_back();
s.insert({occ[c[i]].back(),c[i]});
}
}
#include "assistant.h"
#include <bits/stdc++.h>
using namespace std;
int get_dig2(int k){
int ret = 1;
while((1<<ret) < k + 1){
ret++;
}
return ret;
}
struct BIT{
vector<int> bit;
int n;
BIT(int size){
n = size+5;
bit.assign(n,0);
}
void upd(int pos,int val){
for(++pos;pos < n;pos += pos & -pos){
bit[pos] += val;
}
}
int get(int pos){
int ret = 0;
for(++pos;pos > 0;pos -= pos & -pos){
ret += bit[pos];
}
return ret;
}
int get(int l,int r){
return get(r) - get(l-1);
}
int get_kth(int k){
int pos = 0;
for(int i = 20;i>=0;i--){
if( pos + (1<<i) < n && bit[pos + (1<<i)] < k){
k -= bit[pos + (1<<i)];
pos += (1<<i);
}
}
return pos;
}
};
void Assist(unsigned char *a, int n, int k, int r) {
int dig = get_dig2(k);
BIT bt(n);
for(int i = 0;i<k;i++){
bt.upd(i,1);
}
int last = 0;
for (int i = 0; i < n; i++) {
int req = GetRequest();
int num = 0;
for(int j = dig-1;j>=0;j--){
num += (1<<j) * a[last];
last++;
}
if(num != 0){
PutBack(bt.get_kth(num));
bt.upd(bt.get_kth(num),-1);
bt.upd(req,1);
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
4 ms |
740 KB |
Output is correct |
4 |
Correct |
5 ms |
952 KB |
Output is correct |
5 |
Correct |
5 ms |
1084 KB |
Output is correct |
6 |
Correct |
10 ms |
1280 KB |
Output is correct |
7 |
Correct |
10 ms |
1380 KB |
Output is correct |
8 |
Correct |
13 ms |
1416 KB |
Output is correct |
9 |
Correct |
13 ms |
1296 KB |
Output is correct |
10 |
Correct |
17 ms |
1400 KB |
Output is correct |
11 |
Correct |
14 ms |
1432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
2228 KB |
Output is correct |
2 |
Correct |
142 ms |
9208 KB |
Output is correct |
3 |
Correct |
378 ms |
20824 KB |
Output is correct |
4 |
Correct |
196 ms |
13260 KB |
Output is correct |
5 |
Correct |
268 ms |
15608 KB |
Output is correct |
6 |
Correct |
313 ms |
17804 KB |
Output is correct |
7 |
Correct |
355 ms |
19632 KB |
Output is correct |
8 |
Correct |
299 ms |
16872 KB |
Output is correct |
9 |
Correct |
146 ms |
12540 KB |
Output is correct |
10 |
Correct |
361 ms |
19972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
287 ms |
16092 KB |
Output is correct |
2 |
Correct |
366 ms |
19876 KB |
Output is correct |
3 |
Correct |
364 ms |
19736 KB |
Output is correct |
4 |
Correct |
350 ms |
19964 KB |
Output is correct |
5 |
Correct |
348 ms |
19824 KB |
Output is correct |
6 |
Correct |
356 ms |
19796 KB |
Output is correct |
7 |
Correct |
362 ms |
20004 KB |
Output is correct |
8 |
Correct |
362 ms |
19796 KB |
Output is correct |
9 |
Correct |
337 ms |
20320 KB |
Output is correct |
10 |
Correct |
359 ms |
19828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
920 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
359 ms |
19672 KB |
Output is partially correct - 1500000 bits used |
2 |
Correct |
362 ms |
19604 KB |
Output is partially correct - 1500000 bits used |
3 |
Correct |
363 ms |
19828 KB |
Output is partially correct - 1500000 bits used |
4 |
Correct |
353 ms |
19804 KB |
Output is partially correct - 1500000 bits used |
5 |
Correct |
358 ms |
19812 KB |
Output is partially correct - 1500000 bits used |
6 |
Correct |
367 ms |
19816 KB |
Output is partially correct - 1500000 bits used |
7 |
Correct |
372 ms |
19808 KB |
Output is partially correct - 1497585 bits used |
8 |
Correct |
359 ms |
19908 KB |
Output is partially correct - 1500000 bits used |
9 |
Correct |
356 ms |
19892 KB |
Output is partially correct - 1500000 bits used |
10 |
Correct |
356 ms |
19760 KB |
Output is partially correct - 1500000 bits used |