#include <bits/stdc++.h>
#include "advisor.h"
using namespace std;
#define pii pair<int, int>
void ComputeAdvice(int *C, int N, int K, int M)
{
int H = K+N;
vector<int> next(H, 0);
vector<int> last(N, 1e9);
for (int i = N-1; i >= 0; i--)
{
next[i+K] = last[C[i]];
last[C[i]]=i+K;
}
for (int i = 0; i < K; i++)
{
next[i] = last[i];
}
set<pii> follow;
vector<int> first(N, -1);
vector<int> ins(N, 0);
vector<int> del(N+K, 0);
vector<int> CC(H);
for (int i = 0; i < K; i++) CC[i] = i;
for (int i = 0; i < N; i++) CC[i+K] = C[i];
for (int i = 0; i < K; i++)
{
first[i] = i;
follow.insert({next[i], i});
ins[i] = 1;
}
for (int i = K; i < H; i++)
{
if (ins[CC[i]])
{
follow.erase({i, first[CC[i]]});
follow.insert({next[CC[i]], i});
continue;
}
else
{
auto [a, b] = *(--follow.end());
follow.erase({a, b});
ins[CC[b]] = 0;
del[b] = 1;
ins[CC[i]] = 1;
follow.insert({next[CC[i]], i});
}
first[CC[i]] = i;
}
for (int i = 0; i < H; i++)
{
cout << del[i] << endl;
WriteAdvice(del[i]);
}
}
#include <bits/stdc++.h>
#include "assistant.h"
using namespace std;
void Assist(unsigned char *A, int N, int K, int R)
{
queue<int> del;
vector<int> ins(N, 0);
for (int i = 0; i < K; i++)
{
ins[i] = 1;
if (A[i]) del.push(i);
}
for (int i = K; i < N+K; i++)
{
int g = GetRequest();
if (A[i]) del.push(g);
if (ins[g]) continue;
ins[del.front()]=0;
ins[g] = 1;
PutBack(del.front());
del.pop();
}
}
Compilation message
advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:46:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
46 | auto [a, b] = *(--follow.end());
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
784 KB |
Error - Invalid Access |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
1448 KB |
Error - Invalid Access |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
132 ms |
6960 KB |
Error - Invalid Access |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
1100 KB |
Error - Invalid Access |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
163 ms |
7972 KB |
Error - Invalid Access |
2 |
Incorrect |
161 ms |
7976 KB |
Error - Invalid Access |
3 |
Incorrect |
169 ms |
8244 KB |
Error - Invalid Access |
4 |
Incorrect |
163 ms |
8272 KB |
Error - Invalid Access |
5 |
Incorrect |
167 ms |
8388 KB |
Error - Invalid Access |
6 |
Incorrect |
224 ms |
8256 KB |
Error - Invalid Access |
7 |
Incorrect |
172 ms |
8260 KB |
Error - Invalid Access |
8 |
Incorrect |
165 ms |
8456 KB |
Error - Invalid Access |
9 |
Incorrect |
167 ms |
8248 KB |
Error - Invalid Access |
10 |
Incorrect |
157 ms |
7484 KB |
Error - Invalid Access |