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>
#include "advisor.h"
template <class T> using Vec = std::vector<T>;
void ComputeAdvice(int *C, int N, int K, int M) {
Vec<std::queue<int>> appear(N);
for (int i = 0; i < N; ++i) {
appear[C[i]].push(i);
}
for (int i = 0; i < N; ++i) {
appear[i].push(N);
}
std::set<std::pair<int, int>> heap;
Vec<int> when(N, -2);
for (int i = 0; i < K; ++i) {
heap.emplace(appear[i].front(), i);
when[i] = -1;
}
Vec<char> send(N + K);
for (int i = 0; i < N; ++i) {
if (when[C[i]] == -2) {
assert(!heap.empty());
const int k = heap.rbegin() -> second;
heap.erase(std::prev(heap.end()));
if (when[k] == -1) {
send[k] = true;
} else {
send[K + when[k]] = true;
}
when[k] = -2;
} else {
heap.erase(std::make_pair(appear[C[i]].front(), i));
}
appear[C[i]].pop();
heap.emplace(appear[C[i]].front(), i);
when[C[i]] = i;
}
for (int i = 0; i < N; ++i) {
if (when[i] != -2) {
if (when[i] == -1) {
send[i] = true;
} else {
send[K + when[i]] = true;
}
}
}
for (const auto x : send) {
WriteAdvice(x);
}
}
#include <bits/stdc++.h>
#include "assistant.h"
template <class T> using Vec = std::vector<T>;
void Assist(unsigned char *A, int N, int K, int R) {
Vec<char> has(N);
std::queue<int> dispose;
for (int i = 0; i < K; ++i) {
has[i] = true;
if (A[i]) {
dispose.push(i);
}
}
for (int i = 0; i < N; ++i) {
const int k = GetRequest();
if (!has[k]) {
assert(!dispose.empty());
PutBack(dispose.front());
has[dispose.front()] = false;
dispose.pop();
has[k] = true;
}
if (A[K + i]) {
dispose.push(k);
}
}
}
# | 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... |