Submission #431039

#TimeUsernameProblemLanguageResultExecution timeMemory
431039KoDLast supper (IOI12_supper)C++17
0 / 100
245 ms74776 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...