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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define ALL(i) i.begin(), i.end()
#define SZ(i) int(i.size())
#define X first
#define Y second
#ifdef tmd
#define debug(...) fprintf(stderr,"#%d-(%s)=",__LINE__,#__VA_ARGS__);_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y) {cerr<<x<<",";_do(y...);}
template<typename IT> ostream& __printRng (ostream& os, IT bg, IT ed) {
for (IT it=bg;it!=ed;it++) {
if (it == bg) os << "{" << *it;
else os << "," << *it;
}
return os << "}";
}
template<typename T> ostream& operator << (ostream& os, const vector<T> &vec) {
return __printRng(os, ALL(vec));
}
template<typename T, typename S> ostream& operator << (ostream& os, const pair<T,S> &pa) {
return os << "{" << pa.X << "," << pa.Y << "}";
}
#else
#define debug(...)
#endif
#include "advisor.h"
const int BB = 25001;
void ComputeAdvice(int *c, int n, int k, int m) {
vector<int> nxt(n);
vector<int> lst(n, n);
for (int i=n-1; i>=0; i--) {
nxt[i] = lst[c[i]];
lst[c[i]] = i;
}
set<pii> pq;
set<int> st;
map<int,int> pos;
for (int i=0; i<k; i++) {
pos[i] = i;
pq.emplace(pii(lst[i], i));
st.insert(i);
debug(lst[i], i);
}
vector<int> pl(k);
iota(pl.begin(), pl.end(), 0);
for (int i=0; i<n; i++) {
int req = c[i];
assert(c[i] == req);
bool flag = true;
if (!st.count(req)) {
pii cur = *prev(pq.end());
pq.erase(prev(pq.end()));
debug(cur);
debug(nxt[i], req);
pl[pos[cur.Y]] = req;
pos[req] = pos[cur.Y];
st.erase(cur.Y);
st.insert(req);
pq.emplace(nxt[i], req);
} else {
flag = false;
pq.erase({i, req});
pq.emplace(nxt[i], req);
}
int info = flag ? pos[req] : BB;
for (int j=0; j<15; j++) {
WriteAdvice((info>>j) & 1);
}
}
debug("done");
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define ALL(i) i.begin(), i.end()
#define SZ(i) int(i.size())
#define X first
#define Y second
#ifdef tmd
#define debug(...) fprintf(stderr,"#%d-(%s)=",__LINE__,#__VA_ARGS__);_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y) {cerr<<x<<",";_do(y...);}
template<typename IT> ostream& __printRng (ostream& os, IT bg, IT ed) {
for (IT it=bg;it!=ed;it++) {
if (it == bg) os << "{" << *it;
else os << "," << *it;
}
return os << "}";
}
template<typename T> ostream& operator << (ostream& os, const vector<T> &vec) {
return __printRng(os, ALL(vec));
}
template<typename T, typename S> ostream& operator << (ostream& os, const pair<T,S> &pa) {
return os << "{" << pa.X << "," << pa.Y << "}";
}
#else
#define debug(...)
#endif
#include "assistant.h"
const int BB = 25001;
void Assist(unsigned char *a, int n, int k, int r) {
vector<int> pl(k);
iota(ALL(pl), 0);
for (int i=0, ptr=0; i<n; i++) {
int req = GetRequest();
int kid = 0;
for (int j=0; j<15; j++) {
if (a[ptr++]) kid += 1<<j;
}
debug(kid);
if (kid != BB) {
PutBack(pl[kid]);
pl[kid] = req;
}
}
}
# | 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... |