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 <bits/stdc++.h>
using namespace std;
#include <bits/extc++.h>
using namespace __gnu_pbds;
template <typename T>
using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T, typename V>
using pbds_map = tree<T, V, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void ComputeAdvice(int *c, int n, int k, int m) {
vector<queue<int>> nextocc(n);
for (int i = 0; i<n; i++){
nextocc[c[i]].push(i);
}
int bitwidth = ceil(log2(k));
set<pair<int,int>> scaffrem;
pbds_set<int> scaff;
for (int i = 0; i<k; i++){
if (nextocc[i].size()>0){
scaffrem.insert({nextocc[i].front(),i});
} else {
scaffrem.insert({n,i});
}
scaff.insert(i);
}
for (int i = 0; i<n; i++){
//cout<<i<<'\n';
if (scaff.find(c[i])!=scaff.end()){
scaffrem.erase({nextocc[c[i]].front(),c[i]});
} else {
//check if the one we just put on can be removed
auto toremove = prev(scaffrem.end());
int ind;
if (i>0&&nextocc[c[i-1]].size()==0&&c[i]!=c[i-1]){
//cout<<"remove\n";
WriteAdvice(1);
toremove = scaffrem.find({n,c[i-1]});
ind = scaff.order_of_key(toremove->second);
} else {
//cout<<"take\n";
//can we get rid of one we've already used
/*auto it = scaffrem.lower_bound({i,-1});
if (it!=scaffrem.begin()){
toremove = prev(it);
}*/
//transmit ind
ind = scaff.order_of_key(toremove->second);
if (toremove->second==c[i-1]){
WriteAdvice(1);
} else {
WriteAdvice(0);
for (int i = bitwidth-1; i>=0; i--){
WriteAdvice(bool((1<<i)&ind));
}
}
}
scaffrem.erase(toremove);
scaff.erase(scaff.find_by_order(ind));
scaff.insert(c[i]);
}
int newind = n;
nextocc[c[i]].pop();
if (nextocc[c[i]].size()>0){
newind=nextocc[c[i]].front();
}
scaffrem.insert({newind,c[i]});
}
}
#include "assistant.h"
#include <bits/stdc++.h>
using namespace std;
#include <bits/extc++.h>
using namespace __gnu_pbds;
template <typename T>
using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T, typename V>
using pbds_map = tree<T, V, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void Assist(unsigned char *A, int n, int k, int r) {
//GetRequest()
//PutBack()
int ptr = 0;
int bitwidth = ceil(log2(k));
pbds_set<int> scaff;
for (int i = 0; i<k; i++){
scaff.insert(i);
}
int prevcol = -1;
for (int i = 0; i<n; i++){
int col = GetRequest();
if (scaff.find(col)!=scaff.end()){
prevcol=col;
continue;
} else {
int removeLast = A[ptr];
//cout<<ptr<<" "<<int(A[ptr])<<'\n';
ptr++;
auto putel = scaff.begin();
if (removeLast){
putel = scaff.find(prevcol);
} else {
int ind = 0;
for (int i = 0; i<bitwidth; i++){
ind*=2;
ind+=A[ptr];
ptr++;
}
//cout<<ind<<'\n';
putel = scaff.find_by_order(ind);
}
//cout<<"put back "<<*putel<<'\n';
PutBack(*putel);
scaff.erase(putel);
scaff.insert(col);
}
prevcol=col;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |