Submission #288178

#TimeUsernameProblemLanguageResultExecution timeMemory
288178erd1Last supper (IOI12_supper)C++14
43 / 100
521 ms17392 KiB

#include "advisor.h"

#include<bits/stdc++.h>
using namespace std;

#include<bits/extc++.h>
using namespace __gnu_pbds;
template<typename T>
using order_statistics_tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

//#define int lld
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define pb push_back
typedef int64_t lld;
typedef pair<int, int> pii;
typedef long double ld;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> p){
  return out << "(" << p.ff << ", " << p.ss << ")";
}

template<typename Iter>
ostream& outIt(ostream& out, Iter b, Iter e){
  for(Iter i = b; i != e; i++)
    out << (i==b?"":" ") << *i;
  return out;
}

template<typename T>
ostream& operator<<(ostream& out, vector<T> v){
  return outIt(out << '[', all(v)) << ']';
}


template<typename T1, typename T2>
ostream& operator<<(ostream& out, map<T1, T2> m){
  return outIt(out << '{', all(m)) << '}';
}

/*
template<typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
*/

template<typename T1, typename T2>
pair<T1, T2>& operator+=(pair<T1, T2>& a, pair<T1, T2> p){
  return a.ff += p.ff, a.ss += p.ss, a;
}

set<pii> cols;
vector<int> nexts, cn, adv;
order_statistics_tree<int> cols_ord;
void ComputeAdvice(int *C, int N, int K, int M) {
  cn.resize(N, INT_MAX); nexts.resize(N); //adv.resize(N);
  for(int i = N-1; i >= 0; i--){
    nexts[i] = cn[C[i]];
    cn[C[i]] = i;
  }
  //cout << nexts << cn << endl;
  for(int i = 0; i < K; i++)cols.insert({cn[i], i}), cols_ord.insert(i);
  for(int i = 0; i < N; i++){
    //cout << i << endl;
    if(cols_ord.find(C[i]) == cols_ord.end()){
      auto take_out = *prev(cols.end());
      //cout << "oops" << take_out << endl;
      adv.pb((int)cols_ord.order_of_key(take_out.ss));
      cols_ord.erase(take_out.ss);
      cols.erase(take_out);
      cols_ord.insert(C[i]);
    }else{
      cols.erase({cn[C[i]], C[i]});
    }
    cn[C[i]] = nexts[i];
    cols.insert({cn[C[i]], C[i]});
  }
  int bitlen = __lg(K-1)+1;
  //cout << adv << endl;
  for(auto i: adv){
    for(int j = 1; j < K; j <<=1)
      WriteAdvice((i&j)?1:0);
  }
}

#include "assistant.h"

#include<bits/stdc++.h>
using namespace std;

#include<bits/extc++.h>
using namespace __gnu_pbds;
template<typename T>
using order_statistics_tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

//#define int lld
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define pb push_back
typedef int64_t lld;
typedef pair<int, int> pii;
typedef long double ld;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> p){
  return out << "(" << p.ff << ", " << p.ss << ")";
}

template<typename Iter>
ostream& outIt(ostream& out, Iter b, Iter e){
  for(Iter i = b; i != e; i++)
    out << (i==b?"":" ") << *i;
  return out;
}

template<typename T>
ostream& operator<<(ostream& out, vector<T> v){
  return outIt(out << '[', all(v)) << ']';
}


template<typename T1, typename T2>
ostream& operator<<(ostream& out, map<T1, T2> m){
  return outIt(out << '{', all(m)) << '}';
}

//template<typename T>
//using min_heap = priority_queue<T, vector<T>, greater<T>>;

template<typename T1, typename T2>
pair<T1, T2>& operator+=(pair<T1, T2>& a, pair<T1, T2> p){
  return a.ff += p.ff, a.ss += p.ss, a;
}



/*
void ComputeAdvice(int *C, int N, int K, int M) {
  cn.resize(N, INT_MAX); nexts.resize(N); //adv.resize(N);
  for(int i = N-1; i >= 0; i--){
    nexts[i] = cn[C[i]];
    cn[C[i]] = i;
  }
  //cout << nexts << cn << endl;
  for(int i = 0; i < K; i++)cols.insert({cn[i], i}), cols_ord.insert(i);
  for(int i = 0; i < N; i++){
    //cout << i << endl;
    if(cols_ord.find(C[i]) == cols_ord.end()){
      auto take_out = *prev(cols.end());
      //cout << "oops" << take_out << endl;
      adv.pb((int)cols_ord.order_of_key(take_out.ss));
      cols_ord.erase(take_out.ss);
      cols.erase(take_out);
      cols_ord.insert(C[i]);
    }else{
      cols.erase({cn[C[i]], C[i]});
    }
    cn[C[i]] = nexts[i];
    cols.insert({cn[C[i]], C[i]});
  }
  int bitlen = __lg(K-1)+1;
  for(auto i: adv){
    for(int j = 1; j < K; j <<=1)
      WriteAdvice(i&j);
  }
}
*/

vector<int> tadv;
order_statistics_tree<int> tcols_ord;

void Assist(unsigned char *A, int N, int K, int R) {
  int bitlen = __lg(K)+1;
  tadv.resize(N);
  for(int i = 0, k = 0; i < R; k++)
    for(int j = 1; j < K; j<<=1, i++)
      tadv[k] += j*A[i];
  //cout << tadv << endl;
  for(int i = 0; i < K; i++)tcols_ord.insert(i);
  for (int i = 0, j = 0, x; i < N; i++) {
    int req = GetRequest();
    if(tcols_ord.find(req) == tcols_ord.end())
      x = *tcols_ord.find_by_order(tadv[j++]), PutBack(x), tcols_ord.erase(x), tcols_ord.insert(req);
  }
}

Compilation message (stderr)

advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:80:7: warning: unused variable 'bitlen' [-Wunused-variable]
   80 |   int bitlen = __lg(K-1)+1;
      |       ^~~~~~

assistant.cpp: In function 'void Assist(unsigned char*, int, int, int)':
assistant.cpp:90:7: warning: unused variable 'bitlen' [-Wunused-variable]
   90 |   int bitlen = __lg(K)+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...