This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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});
memset(del_val, -1, sizeof(del_val));
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[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) {
/* for (int i = 0; i < R; i++) {
cerr << (int)A[i] << ' ';
}
exit(0); */
set <int> a[2];
rep(i, 0, K - 1) a[A[i]].insert(i);
rep(i, K, K + N - 1) {
int val = GetRequest();
/* rep(j, 0, 1) {
cerr << j << " -> ";
for (auto it : a[j]) cerr << it << ' ';
cerr << endl;
} */
if (a[0].count(val) || a[1].count(val)) {
rep(j, 0, 1) a[j].erase(val);
a[A[i]].insert(val);
continue;
}
//cerr << " -> " << *a[0].begin() << endl;
PutBack(*a[0].begin());
a[0].erase(a[0].begin());
rep(j, 0, 1) a[j].erase(val);
a[A[i]].insert(val);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |