Submission #574783

#TimeUsernameProblemLanguageResultExecution timeMemory
574783FatihSolakLast supper (IOI12_supper)C++17
43 / 100
357 ms16380 KiB
#include "advisor.h" #include <bits/stdc++.h> using namespace std; int get_dig(int k){ int ret = 1; while((1<<ret) < k + 1){ ret++; } return ret; } struct BIT{ vector<int> bit; int n; BIT(int size){ n = size+5; bit.assign(n,0); } void upd(int pos,int val){ for(++pos;pos < n;pos += pos & -pos){ bit[pos] += val; } } int get(int pos){ int ret = 0; for(++pos;pos > 0;pos -= pos & -pos){ ret += bit[pos]; } return ret; } int get(int l,int r){ return get(r) - get(l-1); } }; void write(int x,int dig){ for(int i = dig-1;i>=0;i--){ if((1<<i) <= x){ WriteAdvice(1); //cout << 1; x -= (1<<i); } else{ WriteAdvice(0); //cout <<0; } } //cout << endl; } void ComputeAdvice(int *c, int n, int k, int m){ int dig = get_dig(k); vector<int> occ[n]; for(int i = n-1;i>=0;i--){ occ[i].push_back(n); } for(int i = n-1;i>=0;i--){ occ[c[i]].push_back(i); } set<pair<int,int>> s; BIT bt(n); for(int i = 0;i<k;i++){ bt.upd(i,1); s.insert({occ[i].back(),i}); } for(int i = 0;i<n;i++){ if(bt.get(c[i],c[i]) == 1){ //write(0,dig); s.erase({occ[c[i]].back(),c[i]}); } else{ //cout << s.rbegin()->second << endl; write(bt.get(0,s.rbegin()->second),dig); bt.upd(s.rbegin()->second,-1); bt.upd(c[i],1); s.erase(*s.rbegin()); } occ[c[i]].pop_back(); s.insert({occ[c[i]].back(),c[i]}); } }
#include "assistant.h" #include <bits/stdc++.h> using namespace std; int get_dig2(int k){ int ret = 1; while((1<<ret) < k + 1){ ret++; } return ret; } struct BIT{ vector<int> bit; int n; BIT(int size){ n = size+5; bit.assign(n,0); } void upd(int pos,int val){ for(++pos;pos < n;pos += pos & -pos){ bit[pos] += val; } } int get(int pos){ int ret = 0; for(++pos;pos > 0;pos -= pos & -pos){ ret += bit[pos]; } return ret; } int get(int l,int r){ return get(r) - get(l-1); } int get_kth(int k){ int pos = 0; for(int i = 20;i>=0;i--){ if( pos + (1<<i) < n && bit[pos + (1<<i)] < k){ k -= bit[pos + (1<<i)]; pos += (1<<i); } } return pos; } }; void Assist(unsigned char *a, int n, int k, int r) { int dig = get_dig2(k); BIT bt(n); for(int i = 0;i<k;i++){ bt.upd(i,1); } int last = 0; for (int i = 0; i < n; i++) { int req = GetRequest(); if(bt.get(req,req) == 1)continue; int num = 0; for(int j = dig-1;j>=0;j--){ num += (1<<j) * a[last]; last++; } if(num != 0){ PutBack(bt.get_kth(num)); bt.upd(bt.get_kth(num),-1); bt.upd(req,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...