Submission #1234433

#TimeUsernameProblemLanguageResultExecution timeMemory
1234433Zbyszek99Last supper (IOI12_supper)C++20
100 / 100
104 ms9044 KiB
#include "advisor.h"
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define siz(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
//ll los(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;

vi pozy[100'001];
int cur_poz[100'001];
bool was[200'001];
int cur_in[100'001];
int n;

int next_(int c)
{
    if(cur_poz[c] == siz(pozy[c])) return n+1;
    return pozy[c][cur_poz[c]];
}

void ComputeAdvice(int *C, int N, int k, int M) 
{
    n = N;
    rep(i,n) cur_in[i] = -1;
    rep(i,n)
    {
        pozy[C[i]].pb(i);
    }
    set<pii> used;
    rep(i,k)
    {
        used.insert({-next_(i),i});
        cur_in[i] = i;
    }
    rep(i,n)
    {
        cur_poz[C[i]]++;
        if(cur_in[C[i]] != -1)
        {
            was[cur_in[C[i]]] = 1;
            cur_in[C[i]] = i+k;
            used.erase(used.find({-i,C[i]}));
            used.insert({-next_(C[i]),C[i]});
        }
        else
        {
            auto it = used.begin();
            cur_in[(*it).ss] = -1;
            used.erase(it);
            cur_in[C[i]] = i+k;
            used.insert({-next_(C[i]),C[i]});
        }
    }
    rep(i,n+k)
    {
        WriteAdvice(was[i]);
    }
}
#include "assistant.h"
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define siz(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
//ll los(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;

void Assist(unsigned char *A, int n, int k, int R) 
{
    set<int> to_del;
    set<int> cur_in;
    rep(i,k)
    {
        if(!A[i]) to_del.insert(i);
        cur_in.insert(i);
    }
    int cnt =0;
    rep2(i,k,n+k-1)
    {
        int r = GetRequest();
        if(cur_in.find(r) == cur_in.end())
        {
            cnt++;
            auto it = to_del.begin();
            cur_in.erase(cur_in.find(*it));
            cur_in.insert(r);
            PutBack(*it);
            to_del.erase(it);
            if(!A[i]) to_del.insert(r);
        }
        else
        {
            if(!A[i]) to_del.insert(r);
        }
    }
    cerr << cnt << " ans\n";
}
#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...