Submission #349843

#TimeUsernameProblemLanguageResultExecution timeMemory
349843talant117408Last supper (IOI12_supper)C++17
100 / 100
162 ms13712 KiB
#include "advisor.h"
#include <bits/stdc++.h>
#ifndef EVAL
#include "grader.cpp"
#endif

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define OK cout << "OK" << endl;

void ComputeAdvice(int *c, int n, int k, int m) {
    set <pii> K;
    vector <int> in_K(n), in_N(n), used(n), met(n);
    vector <vector <int>> pos(n);
    
    for(int i = 0; i < n; i++){
        if(c[i] < k && !used[c[i]]){
            used[c[i]]++;
            K.insert(mp(i, c[i]));
        }
        pos[c[i]].pb(i);
    }
    for(int i = 0; i < n; i++) pos[i].pb(n);
    for(int i = 0; i < k; i++){
        if(!used[i]) K.insert(mp(n, i));
    }
    for(int i = 0; i < n; i++){
        used[i] = 0;
        if(i < k) used[i] = 1;
    }
    
    vector <int> last(n, -1);
    
    for(int i = 0; i < n; i++){
        met[c[i]]++;
        last[c[i]] = i;
        if(!used[c[i]]){
            auto to = (*K.rbegin());
            K.erase(to);
            if(!met[to.second]) in_K[to.second] = 1;
            else in_N[last[to.second]] = 1;
            used[to.second] = 0;
            used[c[i]] = 1;
            auto it = ub(all(pos[c[i]]), i);
            K.insert(mp(*it, c[i]));
        }
        else{
            auto it2 = K.find(mp(i, c[i]));
            if(it2 != K.end()){
                auto p = ub(all(pos[c[i]]), i);
                K.erase(it2);
                K.insert(mp(*p, c[i]));
            }
        }
    }
    
    for(int i = 0; i < k; i++){
        WriteAdvice(in_K[i]);
    }
    for(int i = 0; i < n; i++){
        WriteAdvice(in_N[i]);
    }
}
/*
9 3 27
3 2 0 4 1 3 0 0 1
*/
#include "assistant.h"
#include <bits/stdc++.h>
#ifndef EVAL
#include "grader.cpp"
#endif

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define OK cout << "OK" << endl;

void Assist(unsigned char *a, int n, int k, int r) {
    vector <int> v(n), used(n);
    int ptr = 0;
    for(int i = 0; i < k; i++) used[i] = 1;
    for(int i = 0; i < n; i++){
        int cur = GetRequest();
        v[i] = cur;
        if(used[cur] == 0){
            while(ptr < r && !a[ptr]) ptr++;
            if(ptr < k){
                used[ptr] = 0;
                PutBack(ptr);
            }
            else{
                used[v[ptr-k]] = 0;
                PutBack(v[ptr-k]);
            }
            ptr++;
            used[cur] = 1;
        }
    }
}
#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...