이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "advisor.h"
#include <bits/stdc++.h>
// TODO: check k = 1
using namespace std;
#define X first
#define Y second
#define all(x) (x).begin(), (x).end()
const int MAXN = 1e6 + 10;
typedef pair<int, int> pll;
int n, k, m;
vector<int> vec[MAXN];
inline int wtf(int k) {
int ans = 1, res = 0;
while (ans < k)
ans *= 2, res++;
return res;
}
inline void put(int x) {
for (int i = m - 1; i >= 0; i--)
WriteAdvice(x >> i & 1);
}
inline int get(int c, int i) {
return *lower_bound(all(vec[c]), i);
}
void ComputeAdvice(int *C, int N, int K, int M) {
n = N, k = K;
m = wtf(n);
for (int i = 0; i < n; i++)
vec[C[i]].push_back(i);
for (int i = 0; i < n; i++)
vec[i].push_back(n);
set<pll> st;
for (int i = 0; i < k; i++)
st.insert(pll(get(i, 0), i));
for (int i = 0; i < n; i++) {
int c = C[i];
if (st.find(pll(get(c, i), c)) != st.end()) {
st.erase(pll(get(c, i), c));
} else {
put(st.rbegin() -> Y);
st.erase(prev(st.end()));
}
st.insert(pll(get(c, i + 1), c));
}
}
#include "assistant.h"
#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef pair<int, int> pll;
inline int wtf(int k) {
int ans = 1, res = 0;
while (ans < k)
ans *= 2, res++;
return res;
}
void Assist(unsigned char *A, int N, int K, int R) {
int n = N, k = K, m = wtf(n);
set<int> st;
for (int i = 0; i < k; i++)
st.insert(i);
int ind = 0;
for (int i = 0; i < n; i++) {
int c = GetRequest();
if (st.find(c) != st.end()) continue;
int x = 0;
for (int i = m - 1; i >= 0; i--) {
x <<= 1;
x |= A[ind];
ind++;
}
PutBack(x);
st.erase(x);
st.insert(c);
}
}
# | 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... |