#include "advisor.h"
int sz=1;
struct NUse{
int ix;
int nxt;
bool operator<(NUse &nu) const{
return nxt < nu.nxt;
}
}q[150001];
void swap(int &a, int &b){ a ^= b ^= a ^= b; }
void push(NUse nu){
q[sz] = nu;
int curr = sz++;
while (curr != 1){
if (q[curr>>1] < q[curr]){
swap(q[curr].ix, q[curr >> 1].ix);
swap(q[curr].nxt, q[curr >> 1].nxt);
}
else break;
curr >>= 1;
}
}
void pop(){
q[1] = q[--sz];
int curr = 1;
int nxt = 2;
while (nxt < sz){
if (nxt + 1 < sz && q[nxt] < q[1+nxt])
nxt++;
if (q[curr] < q[nxt]){
swap(q[curr].ix, q[nxt].ix);
swap(q[curr].nxt, q[nxt].nxt);
curr = nxt;
nxt += nxt;
}
else break;
}
}
void ComputeAdvice(int *C, int N, int K, int M) {
int nxt[100000] = { 0 };
bool inq[100000] = { 0 };
int right[100000];
int left[100000];
int a[150001] = { 0 };
int i;
for (i = 0; i < N; i++) right[i] = 100001;
for (i = N - 1; i >= 0; --i){
nxt[i] = right[C[i]];
right[C[i]] = i;
}
for (i = 0; i < K; i++) push({ i, right[i] }), inq[i] = 1, left[i]=i;
for (i = 0; i < N; i++){
while (!inq[q[1].ix]) pop();
if (!inq[C[i]]){
a[ left[q[1].ix] ] = 1;
inq[q[1].ix] = 0;
pop();
}
push({ C[i], nxt[i] });
inq[C[i]] = 1;
left[C[i]] = K+i;
}
for (i = 0; i < N + K; i++) WriteAdvice(a[i]^1);
/*WriteAdvice(0);
WriteAdvice(1);
WriteAdvice(2);*/
}
#include "assistant.h"
struct Heap{
int sz = 1;
int p[150001];
int ix[150001];
void swap(int &a, int &b){ a ^= b ^= a ^= b; }
void push(int _p, int _ix){
p[sz] = _p;
ix[sz] = _ix;
int curr = sz++;
while (curr != 1 && p[curr] < p[curr >> 1]){
swap(p[curr], p[curr >> 1]);
swap(ix[curr], ix[curr >> 1]);
curr >>= 1;
}
}
void pop(){
p[1] = p[--sz];
ix[1] = ix[sz];
int curr = 1;
int nxt = 2;
while (nxt < sz){
if (nxt + 1 < sz&&p[nxt] > p[nxt + 1]) nxt++;
if (p[curr]>p[nxt]){
swap(p[nxt], p[curr]);
swap(ix[nxt], ix[curr]);
curr = nxt;
nxt += nxt;
}
else break;
}
}
}pq;
void Assist(unsigned char *A, int N, int K, int R) {
int i;
int a_ix = 0;
bool inq[100000] = { 0 };
for (i = 0; i < K; i++){
pq.push(A[a_ix++],i);
inq[i] = 1;
}
for (i = 0; i < N; i++){
int req = GetRequest();
while (!inq[pq.ix[1]]) pq.pop();
if (!inq[req]){
PutBack(pq.ix[1]);
inq[pq.ix[1]] = 0;
pq.pop();
}
pq.push(A[a_ix++],req);
inq[req] = 1;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2800 KB |
Output is correct |
2 |
Correct |
5 ms |
3032 KB |
Output is correct |
3 |
Correct |
5 ms |
3528 KB |
Output is correct |
4 |
Correct |
7 ms |
3528 KB |
Output is correct |
5 |
Correct |
10 ms |
3664 KB |
Output is correct |
6 |
Correct |
12 ms |
3696 KB |
Output is correct |
7 |
Correct |
8 ms |
3744 KB |
Output is correct |
8 |
Correct |
9 ms |
3808 KB |
Output is correct |
9 |
Correct |
10 ms |
3808 KB |
Output is correct |
10 |
Correct |
9 ms |
3808 KB |
Output is correct |
11 |
Correct |
9 ms |
3808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
4064 KB |
Output is correct |
2 |
Correct |
56 ms |
6112 KB |
Output is correct |
3 |
Correct |
156 ms |
8928 KB |
Output is correct |
4 |
Correct |
110 ms |
8928 KB |
Output is correct |
5 |
Correct |
108 ms |
9952 KB |
Output is correct |
6 |
Correct |
98 ms |
11768 KB |
Output is correct |
7 |
Correct |
88 ms |
13472 KB |
Output is correct |
8 |
Correct |
147 ms |
13512 KB |
Output is correct |
9 |
Correct |
117 ms |
14416 KB |
Output is correct |
10 |
Correct |
165 ms |
17160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
118 ms |
17160 KB |
Output is correct |
2 |
Correct |
90 ms |
17160 KB |
Output is correct |
3 |
Correct |
115 ms |
17160 KB |
Output is correct |
4 |
Correct |
107 ms |
17160 KB |
Output is correct |
5 |
Correct |
83 ms |
17160 KB |
Output is correct |
6 |
Correct |
86 ms |
17160 KB |
Output is correct |
7 |
Correct |
85 ms |
17160 KB |
Output is correct |
8 |
Correct |
111 ms |
17160 KB |
Output is correct |
9 |
Correct |
82 ms |
17312 KB |
Output is correct |
10 |
Correct |
87 ms |
17312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
17312 KB |
Output is correct |
2 |
Correct |
8 ms |
17312 KB |
Output is correct |
3 |
Correct |
10 ms |
17312 KB |
Output is correct |
4 |
Correct |
9 ms |
17312 KB |
Output is correct |
5 |
Correct |
8 ms |
17312 KB |
Output is correct |
6 |
Correct |
8 ms |
17312 KB |
Output is correct |
7 |
Correct |
8 ms |
17312 KB |
Output is correct |
8 |
Correct |
10 ms |
17312 KB |
Output is correct |
9 |
Correct |
10 ms |
17312 KB |
Output is correct |
10 |
Correct |
8 ms |
17312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
17312 KB |
Output is correct - 120000 bits used |
2 |
Correct |
90 ms |
17312 KB |
Output is correct - 122000 bits used |
3 |
Correct |
86 ms |
17312 KB |
Output is correct - 125000 bits used |
4 |
Correct |
86 ms |
17312 KB |
Output is correct - 125000 bits used |
5 |
Correct |
152 ms |
17312 KB |
Output is correct - 125000 bits used |
6 |
Correct |
88 ms |
17312 KB |
Output is correct - 125000 bits used |
7 |
Correct |
86 ms |
17312 KB |
Output is correct - 124828 bits used |
8 |
Correct |
118 ms |
17312 KB |
Output is correct - 124910 bits used |
9 |
Correct |
129 ms |
17312 KB |
Output is correct - 125000 bits used |
10 |
Correct |
79 ms |
17312 KB |
Output is correct - 125000 bits used |