#include "advisor.h"
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define pp pop_back
#define sz(x) (int)x.size()
#define rep(z, a, b) for (int z = (a); (z) <= (b); z++)
#define per(z, a, b) for (int z = (a); (z) >= (b); z--)
using namespace std;
const int MAXN = (int)2e5 + 7;
vector <int> nxt[MAXN];
int del_val[MAXN];
bool good[MAXN];
void ComputeAdvice(int *C, int N, int K, int M) {
per(i, N - 1, 0) nxt[i].pb(N);
per(i, N - 1, 0) nxt[C[i]].pb(i);
set < pair <int, int > > st;
rep(i, 0, K - 1) st.insert({nxt[i].back(), i});
int Log = log2(N);
rep(i, 0, N - 1) {
while (sz(st) && st.begin() -> f <= i) {
int x = st.begin() -> s;
st.erase(st.begin());
nxt[x].pp();
st.insert({nxt[x].back(), x});
}
if (st.count({nxt[C[i]].back(), C[i]})) {
continue;
}
int x = st.rbegin() -> s;
st.erase(--st.end());
st.insert({nxt[C[i]].back(), C[i]});
del_val[i] = x;
}
map <int, int> ask, del;
per(i, N - 1, 0) {
/// good if ask < del
if (ask.count(C[i]) && (!del.count(C[i]) || ask[C[i]] < del[C[i]])) {
good[i] = 1;
}
ask[C[i]] = i;
del[del_val[C[i]]] = i;
}
rep(i, 0, K - 1) {
if (ask.count(i) && (!del.count(i) || ask[i] < del[i])) {
WriteAdvice(1);
}
else WriteAdvice(0);
}
rep(i, 0, N - 1) {
WriteAdvice(good[i]);
}
}
#include "assistant.h"
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define pp pop_back
#define sz(x) (int)x.size()
#define rep(z, a, b) for (int z = (a); (z) <= (b); z++)
#define per(z, a, b) for (int z = (a); (z) >= (b); z--)
using namespace std;
const int MAXN = (int)2e5 + 7;
void Assist(unsigned char *A, int N, int K, int R) {
set <int> a[2];
rep(i, 0, K - 1) a[A[i]].insert(i);
rep(i, K, K + N - 1) {
int val = GetRequest();
if (a[0].count(val) || a[1].count(val)) continue;
PutBack(*a[0].begin());
a[0].erase(a[0].begin());
a[A[i]].insert(val);
}
}
Compilation message
advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:30:7: warning: unused variable 'Log' [-Wunused-variable]
int Log = log2(N);
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
9968 KB |
Output is correct |
2 |
Incorrect |
8 ms |
10224 KB |
Error - Putting back a color that is not on the scaffold |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
26 ms |
12272 KB |
Error - Putting back a color that is not on the scaffold |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
213 ms |
27888 KB |
Error - Putting back a color that is not on the scaffold |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
10992 KB |
Error - Putting back a color that is not on the scaffold |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
281 ms |
32096 KB |
Error - Putting back a color that is not on the scaffold |
2 |
Incorrect |
273 ms |
32360 KB |
Error - Putting back a color that is not on the scaffold |
3 |
Incorrect |
289 ms |
32520 KB |
Error - Putting back a color that is not on the scaffold |
4 |
Incorrect |
271 ms |
32696 KB |
Error - Putting back a color that is not on the scaffold |
5 |
Incorrect |
279 ms |
32416 KB |
Error - Putting back a color that is not on the scaffold |
6 |
Incorrect |
280 ms |
32584 KB |
Error - Putting back a color that is not on the scaffold |
7 |
Incorrect |
286 ms |
32568 KB |
Error - Putting back a color that is not on the scaffold |
8 |
Incorrect |
278 ms |
32504 KB |
Error - Putting back a color that is not on the scaffold |
9 |
Incorrect |
278 ms |
32496 KB |
Error - Putting back a color that is not on the scaffold |
10 |
Incorrect |
309 ms |
39408 KB |
Output isn't correct - not an optimal way |