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];
set <int> in;
set < pair <int, int > > dp;
void ComputeAdvice(int *C, int N, int K, int M) {
rep(i, 0, N - 1) {
nxt[i].pb(N);
}
per(i, N - 1, 0) {
nxt[C[i]].pb(i);
}
rep(i, 0, K - 1) {
in.insert(i);
dp.insert({nxt[i].back(), i});
}
int LOG = log2(K);
rep(i, 0, N - 1) {
if (in.count(C[i])) {
WriteAdvice(0);
continue;
}
while (sz(dp) && dp.begin() -> f <= i) {
int x = dp.begin() -> s;
dp.erase(dp.begin());
nxt[x].pp();
dp.insert({nxt[x].back(), x});
}
int del = dp.rbegin() -> s, id = 0;
WriteAdvice(1);
for (auto it : in) {
if (it == del) {
break;
}
++id;
}
dp.erase(--dp.end());
in.erase(del);
in.insert(C[i]);
dp.insert({nxt[C[i]].back(), C[i]});
// cerr << "PUT -> " << del << endl;
rep(j, 0, LOG) {
if (id & (1 << j)) WriteAdvice(1);
else WriteAdvice(0);
}
}
}
#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) {
int LOG = log2(K);
set <int> st;
rep(i, 0, K - 1) st.insert(i);
for (int i = 0; i < R; ) {
int add = GetRequest();
if (A[i] == 0) {
i++;
continue;
}
else {
i++;
int id = 0;
rep(j, 0, LOG) {
if (A[i + j] == 1) id |= 1 << j;
}
int val = -1;
for (auto it : st) {
if (!id) {
val = it;
break;
}
--id;
}
i += LOG + 1;
// cerr << val << " -> " << endl;
PutBack(val);
st.erase(val);
}
st.insert(add);
}
}
# | 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... |