# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
995428 | 8pete8 | Last supper (IOI12_supper) | C++17 | 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 "advisor.h"
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<cassert>
#include<unordered_map>
#include <queue>
#include <cstdint>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric>
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-lopps")
using namespace std;
void ComputeAdvice(int *C, int N, int K, int M){
auto get=[&](int x){for(int i=20;i>=0;i--)if(x&(1<<i))return i;};
vector<int>v,on(N,0),cur(N,0);
K=min(K,N);
vector<int>occ[N+1];
for(int i=0;i<N;i++,C++)v.pb(*C),occ[v.back()].pb(i);
for(int i=0;i<N;i++)occ[i].pb(N);
vector<int>have;
set<pii>pq;
for(int i=0;i<K;i++)pq.insert({occ[i][0],have.size()}),have.pb(i),on[i]=1;
int mx=get(K);
int cnt=0;
for(auto i:v){
if(on[i]){
auto it=pq.lb({occ[i][cur[i]],0});
int pos=(*it).s;
pq.erase(it);
while(cur[i]<occ[i].size()&&occ[i][cur[i]]<=cnt)cur[i]++;
pq.insert({occ[i][cur[i]],pos});
cnt[i]++
continue;
}
if(pq.empty())continue;
int pos=(*prev(pq.end())).s;
pq.erase(prev(pq.end()));
on[have[pos]]=0;
for(int j=0;j<=mx;j++){
if(pos&(1<<j))WriteAdvice(1);
else WriteAdvice(0);
}
while(cur[i]<occ[i].size()&&occ[i][cur[i]]<=cnt)cur[i]++;
pq.insert({occ[i][cur[i]],pos});
have[pos]=i;
on[i]=1;
cnt++;
}
}
#include "assistant.h"
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<cassert>
#include<unordered_map>
#include <queue>
#include <cstdint>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric>
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-lopps")
using namespace std;
void Assist(unsigned char *A, int N, int K, int R){
vector<int>have;
K=min(K,N);
auto get2=[&](int x){for(int i=20;i>=0;i--)if(x&(1<<i))return i;};
vector<int>on(N,0),pos(N,0);
priority_queue<pii>pq;
for(int i=0;i<K;i++)have.pb(i),on[i]=1,pos[i]=i;
int mx=get2(K);
for(int i=0;i<N;i++){
int x=GetRequest();
if(on[x])continue;
int val=0;
for(int j=0;j<=mx;j++,A++)val+=((1<<j)*(*A));
PutBack(have[val]);
on[have[val]]=0;
have[val]=x;
on[x]=1;
}
}
/*
10 2 20000
4 5 5 3 5 8 3 5 2 2
*/