#include "advisor.h"
#include <vector>
#define MAXN 200009
int heap[MAXN], poz[MAXN], d[MAXN];
inline void mySwap(int p, int q) {
int aux = heap[p];
heap[p] = heap[q];
heap[q] = aux;
poz[heap[p]] = p;
poz[heap[q]] = q;
}
inline void urcare(int p) {
while (p > 1 && d[heap[p]] > d[heap[p / 2]]) {
mySwap(p, p / 2);
p /= 2;
}
}
inline void coborare(int p) {
int q;
bool f = 1;
while (f && (q = 2 * p) <= heap[0]) {
if (q < heap[0] && d[heap[q + 1]] > d[heap[q]])
q++;
if (d[heap[q]] > d[heap[p]]) {
mySwap(p, q);
p = q;
} else
f = 0;
}
}
void ComputeAdvice(int *C, int N, int K, int M) {
if (K > N)
K = N;
for (int i = 0; i < N; i++)
d[i] = N;
for (int i = 0; i < N; i++)
if (d[C[i]] == N)
d[C[i]] = i;
for (int i = 0; i < K; i++)
heap[++heap[0]] = i, poz[i] = i + 1;
for (int i = heap[0]; i > 0; i--)
coborare(i);
std::vector < int > urm(N), last(N, N);
for (int i = N - 1; i >= 0; i--) {
urm[i] = last[C[i]];
last[C[i]] = i;
}
std::vector < bool > ans(N + K, 1);
std::vector < int > moment(N, -1);
for (int i = 0; i < K; i++)
moment[i] = i;
for (int i = 0; i < N; i++) {
if (poz[C[i]]) {
d[C[i]] = urm[i];
urcare(poz[C[i]]);
} else {
ans[moment[heap[1]]] = 0;
poz[heap[1]] = 0;
heap[1] = C[i];
poz[C[i]] = 1;
d[heap[1]] = urm[i];
coborare(1);
}
moment[C[i]] = i + K;
}
for (int i = 0; i < N + K; i++)
WriteAdvice(ans[i]);
}
#include "assistant.h"
#include <vector>
void Assist(unsigned char *A, int N, int K, int R) {
if (K > N)
K = N;
std::vector < int > v(K), t(N, 0);
for (int i = 0; i < K; i++)
v[i] = i, t[i] = A[i];
for (int i = 0; i < N; i++) {
int x = GetRequest();
int p = 0;
while (p < K && v[p] != x)
p++;
if (p >= K) {
p = 0;
while (t[v[p]])
p++;
PutBack(v[p]);
v[p] = x;
}
t[x] = A[i + K];
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
776 KB |
Output is correct |
2 |
Correct |
4 ms |
640 KB |
Output is correct |
3 |
Correct |
4 ms |
856 KB |
Output is correct |
4 |
Correct |
7 ms |
792 KB |
Output is correct |
5 |
Correct |
9 ms |
1184 KB |
Output is correct |
6 |
Correct |
9 ms |
1024 KB |
Output is correct |
7 |
Correct |
9 ms |
1056 KB |
Output is correct |
8 |
Correct |
11 ms |
1284 KB |
Output is correct |
9 |
Correct |
12 ms |
1280 KB |
Output is correct |
10 |
Correct |
11 ms |
1024 KB |
Output is correct |
11 |
Correct |
10 ms |
1064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
1280 KB |
Output is correct |
2 |
Correct |
154 ms |
3328 KB |
Output is correct |
3 |
Execution timed out |
2570 ms |
5872 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1039 ms |
4848 KB |
Output is correct |
2 |
Correct |
1352 ms |
5872 KB |
Output is correct |
3 |
Correct |
1410 ms |
5872 KB |
Output is correct |
4 |
Correct |
1372 ms |
5872 KB |
Output is correct |
5 |
Correct |
971 ms |
5872 KB |
Output is correct |
6 |
Correct |
1494 ms |
5888 KB |
Output is correct |
7 |
Correct |
1663 ms |
5872 KB |
Output is correct |
8 |
Correct |
2045 ms |
5872 KB |
Output is correct |
9 |
Correct |
1482 ms |
5872 KB |
Output is correct |
10 |
Correct |
1557 ms |
5872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
796 KB |
Output is correct |
2 |
Correct |
12 ms |
1092 KB |
Output is correct |
3 |
Correct |
8 ms |
1056 KB |
Output is correct |
4 |
Correct |
7 ms |
1168 KB |
Output is correct |
5 |
Correct |
8 ms |
1024 KB |
Output is correct |
6 |
Correct |
11 ms |
1024 KB |
Output is correct |
7 |
Correct |
10 ms |
1280 KB |
Output is correct |
8 |
Correct |
11 ms |
1056 KB |
Output is correct |
9 |
Correct |
10 ms |
1064 KB |
Output is correct |
10 |
Correct |
12 ms |
1064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1423 ms |
5744 KB |
Output is correct - 120000 bits used |
2 |
Correct |
1361 ms |
5872 KB |
Output is correct - 122000 bits used |
3 |
Correct |
1723 ms |
5872 KB |
Output is correct - 125000 bits used |
4 |
Correct |
1687 ms |
6128 KB |
Output is correct - 125000 bits used |
5 |
Correct |
1501 ms |
5872 KB |
Output is correct - 125000 bits used |
6 |
Correct |
1545 ms |
5872 KB |
Output is correct - 125000 bits used |
7 |
Correct |
1617 ms |
5888 KB |
Output is correct - 124828 bits used |
8 |
Correct |
1623 ms |
5888 KB |
Output is correct - 124910 bits used |
9 |
Correct |
1522 ms |
5872 KB |
Output is correct - 125000 bits used |
10 |
Correct |
1637 ms |
6128 KB |
Output is correct - 125000 bits used |