Submission #125049

#TimeUsernameProblemLanguageResultExecution timeMemory
125049RockyBLast supper (IOI12_supper)C++17
29 / 100
461 ms32496 KiB
#include "advisor.h"
#include <bits/stdc++.h>

#define f first
#define s second

#define pb push_back
#define pp pop_back

#define sz(x) (int)x.size()

#define rep(z, a, b) for (int z = (a); (z) <= (b); z++)
#define per(z, a, b) for (int z = (a); (z) >= (b); z--)

using namespace std;

const int MAXN = (int)2e5 + 7;


vector <int> nxt[MAXN];
set <int> in;
set < pair <int, int > > dp;
void ComputeAdvice(int *C, int N, int K, int M) {
  rep(i, 0, N - 1) {
    nxt[i].pb(N);
  }
  per(i, N - 1, 0) {
    nxt[C[i]].pb(i);
  }
  rep(i, 0, K - 1) {
    in.insert(i);
    dp.insert({nxt[i].back(), i});
  }
  int LOG = log2(N);
  rep(i, 0, N - 1) {
    if (in.count(C[i])) {
      WriteAdvice(0);
      continue;
    }

    while (sz(in) && dp.begin() -> f <= i) {
      int x = dp.begin() -> s;
      dp.erase(dp.begin());
      nxt[x].pp();
      dp.insert({nxt[x].back(), x});
    }

    int del = dp.rbegin() -> s;
    dp.erase(--dp.end());
    in.erase(del);
    in.insert(C[i]);
    dp.insert({nxt[C[i]].back(), C[i]});
    WriteAdvice(1);
    // cerr << "PUT -> " << del << endl;
    rep(j, 0, LOG) {
      if (del & (1 << j)) WriteAdvice(1);
      else WriteAdvice(0);
    }
  }
} 
#include "assistant.h"
#include <bits/stdc++.h>

#define f first
#define s second

#define pb push_back
#define pp pop_back

#define sz(x) (int)x.size()

#define rep(z, a, b) for (int z = (a); (z) <= (b); z++)
#define per(z, a, b) for (int z = (a); (z) >= (b); z--)

using namespace std;

const int MAXN = (int)2e5 + 7;

void Assist(unsigned char *A, int N, int K, int R) {
  int LOG = log2(N);
  for (int i = 0; i < R; ) {
    GetRequest();
    if (A[i] == 0) {
      i++;
      continue;
    }
    else {
      i++;
      int val = 0;
      rep(j, 0, LOG) {
        if (A[i + j] == 1) val |= 1 << j;
      }
      i += LOG + 1;
      // cerr << val << " -> " << endl;
      PutBack(val);
    }
  }
}
#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...