#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();
if(bt.get(req,req) == 1)continue;
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);
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
508 KB |
Output is correct |
2 |
Correct |
1 ms |
508 KB |
Output is correct |
3 |
Correct |
1 ms |
644 KB |
Output is correct |
4 |
Correct |
6 ms |
796 KB |
Output is correct |
5 |
Correct |
4 ms |
1060 KB |
Output is correct |
6 |
Correct |
11 ms |
1244 KB |
Output is correct |
7 |
Correct |
4 ms |
1048 KB |
Output is correct |
8 |
Correct |
12 ms |
1260 KB |
Output is correct |
9 |
Correct |
11 ms |
1244 KB |
Output is correct |
10 |
Correct |
8 ms |
1216 KB |
Output is correct |
11 |
Correct |
10 ms |
1232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
1780 KB |
Output is correct |
2 |
Correct |
98 ms |
6512 KB |
Output is correct |
3 |
Correct |
278 ms |
15756 KB |
Output is correct |
4 |
Correct |
217 ms |
11884 KB |
Output is correct |
5 |
Correct |
251 ms |
13940 KB |
Output is correct |
6 |
Correct |
293 ms |
14496 KB |
Output is correct |
7 |
Correct |
242 ms |
14160 KB |
Output is correct |
8 |
Correct |
294 ms |
13900 KB |
Output is correct |
9 |
Correct |
148 ms |
11368 KB |
Output is correct |
10 |
Correct |
221 ms |
13832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
232 ms |
11212 KB |
Output is correct |
2 |
Correct |
242 ms |
13908 KB |
Output is correct |
3 |
Correct |
273 ms |
13956 KB |
Output is correct |
4 |
Correct |
216 ms |
13604 KB |
Output is correct |
5 |
Correct |
184 ms |
12492 KB |
Output is correct |
6 |
Correct |
259 ms |
13964 KB |
Output is correct |
7 |
Correct |
224 ms |
13656 KB |
Output is correct |
8 |
Correct |
357 ms |
16380 KB |
Output is correct |
9 |
Correct |
150 ms |
12504 KB |
Output is correct |
10 |
Correct |
262 ms |
13944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
896 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
234 ms |
14068 KB |
Output is partially correct - 772365 bits used |
2 |
Correct |
295 ms |
13976 KB |
Output is partially correct - 742095 bits used |
3 |
Correct |
230 ms |
14172 KB |
Output is partially correct - 712470 bits used |
4 |
Correct |
258 ms |
14048 KB |
Output is partially correct - 712005 bits used |
5 |
Correct |
231 ms |
14296 KB |
Output is partially correct - 710610 bits used |
6 |
Correct |
291 ms |
13968 KB |
Output is partially correct - 712155 bits used |
7 |
Correct |
225 ms |
13800 KB |
Output is partially correct - 711090 bits used |
8 |
Correct |
243 ms |
13880 KB |
Output is partially correct - 713340 bits used |
9 |
Correct |
224 ms |
14096 KB |
Output is partially correct - 712830 bits used |
10 |
Correct |
317 ms |
16288 KB |
Output is partially correct - 1117620 bits used |