이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "advisor.h"
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#ifndef LOCAL
#define cerr if(false) cerr
#endif
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for(int i = 0; i < n; i ++)
#define revn(i, n) for(int i = n - 1; i >= 0; i --)
typedef long long ll;
template<class T, template<class T2, class A=allocator<T2> > class cont> inline ostream &operator <<(ostream &out, const cont<T> &x) { for(const auto &it : x) { out << it << " ";} return out;}
template<class T, template<class T2, class A=allocator<T2> > class cont> inline istream &operator >>(istream &in, cont<T> &x) { for(auto &it : x) { in >> it;} return in;}
template<class T, class T2> inline ostream &operator <<(ostream &out, const pair<T, T2> &x) { out << x.first << " " << x.second; return out;}
template<class T, class T2> inline istream &operator >>(istream &in, pair<T, T2> &x) { in >> x.first >> x.second; return in;}
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
const int MAX_N = 2e5 + 10;
ll nxt[MAX_N];
ll change[MAX_N];
bool ans[MAX_N];
int n, k, m;
int current[MAX_N];
void ComputeAdvice(int *arr, int n, int k, int m) {
for(int i = 0; i < n; i ++) {
nxt[i] = n;
}
for(int i = n - 1; i >= 0; i --) {
change[i] = nxt[arr[i]];
nxt[arr[i]] = i;
}
set<pair<int, int> > st;
for(int i = 0; i < k; i ++) {
st.insert({nxt[i], i});
current[i] = i;
}
int cnt = k;
auto removeMax = [&st]() {
auto it = st.end();
it --;
ans[current[(*it).second]] = 1;
st.erase(it);
};
for(int i = 0; i < n; i ++) {
if(st.find({i, arr[i]}) != st.end()) {
auto it = st.find({i, arr[i]});
ans[current[(*it).second]] = 0;
st.erase(it);
} else {
removeMax();
}
nxt[arr[i]] = change[i];
current[arr[i]] = cnt ++;
st.insert({nxt[arr[i]], arr[i]});
}
for(int i = 0; i < cnt; i ++) {
WriteAdvice(ans[i]);
}
}
#include "assistant.h"
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#ifndef LOCAL
#define cerr if(false) cerr
#endif
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for(int i = 0; i < n; i ++)
#define revn(i, n) for(int i = n - 1; i >= 0; i --)
typedef long long ll;
template<class T, template<class T2, class A=allocator<T2> > class cont> inline ostream &operator <<(ostream &out, const cont<T> &x) { for(const auto &it : x) { out << it << " ";} return out;}
template<class T, template<class T2, class A=allocator<T2> > class cont> inline istream &operator >>(istream &in, cont<T> &x) { for(auto &it : x) { in >> it;} return in;}
template<class T, class T2> inline ostream &operator <<(ostream &out, const pair<T, T2> &x) { out << x.first << " " << x.second; return out;}
template<class T, class T2> inline istream &operator >>(istream &in, pair<T, T2> &x) { in >> x.first >> x.second; return in;}
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
void Assist(unsigned char *ans, int n, int k, int r) {
set<int> st;
set<int> bad;
for(int i = 0; i < k; i ++) {
st.insert(i);
if(ans[i]) {
bad.insert(i);
}
}
int cnt = k;
for(int i = 0; i < n; i ++) {
int now = GetRequest();
if(st.find(now) != st.end()) {
st.erase(st.find(now));
} else {
auto something = bad.begin();
PutBack(*something);
st.erase(*something);
bad.erase(*something);
}
st.insert(now);
if(ans[cnt]) {
bad.insert(now);
}
cnt ++;
}
}
# | 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... |