# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
829947 | MODDI | Last supper (IOI12_supper) | C++14 | 0 ms | 0 KiB |
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"
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
int n;
stack<int> G[100105];
set<pii> activasion;
set<int> in_pq;
vi advice, out;
void ComputeAdvice(int *C, int N, int K, int M) {
n = N;
for(int i=n-1;i>=0;i--) G[C[i]].push(i);
for(int i=0;i<K;i++){
int when=n+1;
if(!G[i].empty()) when=G[i].top();
activasion.emplace(mp(when, i));
in_pq.insert(i);
}
for(int i = 0; i < n + K; i++) advice.pb(1);
for(int i = 0; i < K; i++) out.pb(i);
for(int i=0;i<n;i++){
G[C[i]].pop();
out[C[i]]=K+i;
if(in_pq.find(C[i])==in_pq.end()){
pii sega =*activasion.begin();
activasion.erase(*activasion.begin());
in_pq.erase(sega.second);
advice[out[sega.second]]=0;
}
int when=0;
in_pq.emplace(C[i]);
if(G[C[i]].empty()) when=n+1;
else when=G[C[i]].top();
activasion.insert(mp(when, C[i]));
}
for(int i = 0; i < n+K; i++)
WriteAdvice(advice[i]);
}