Submission #125068

# Submission time Handle Problem Language Result Execution time Memory
125068 2019-07-04T14:16:26 Z RockyB Last supper (IOI12_supper) C++17
41 / 100
528 ms 34048 KB
#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;


struct tree {
  int t[MAXN << 2];
  void upd(int p, int x, int v = 1, int tl = 0, int tr = MAXN) {
    if (tl == tr) {
      t[v] += x;
      return;
    }
    int tm = tl + tr >> 1;
    if (p <= tm) upd(p, x, v << 1, tl, tm);
    else upd(p, x, v << 1 | 1, tm +1 , tr);
    t[v] = t[v << 1] + t[v << 1 | 1];
  }
  int get(int l, int r, int v = 1, int tl = 0, int tr = MAXN) {
    if (l <= tl && tr <= r) return t[v];
    if (tl > r || tr < l) return 0;
    int tm = tl + tr >> 1;
    return get(l, r, v << 1, tl, tm) + get(l, r, v << 1 | 1, tm + 1, tr);
  }
  int kth(int x, int v = 1, int tl = 0, int tr = MAXN) {
    if (tl == tr) return tl;
    int tm = tl + tr >> 1;
    if (t[v << 1] >= x) return kth(x, v << 1, tl, tm);
    return kth(x - t[v << 1], v << 1 | 1, tm + 1, tr);
  }
} f;

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});
    f.upd(i, 1);
  }
  int LOG = log2(K);
  rep(i, 0, N - 1) {
    if (in.count(C[i])) {
      WriteAdvice(0);
      continue;
    }

    while (sz(dp) && 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, id = f.get(0, del) - 1;
    WriteAdvice(1);
    
    dp.erase(--dp.end());
    in.erase(del);
    in.insert(C[i]);
    f.upd(C[i], 1);
    f.upd(del, -1);
    dp.insert({nxt[C[i]].back(), C[i]});
    // cerr << "PUT -> " << del << endl;
    rep(j, 0, LOG) {
      if (id & (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;

struct fenwick {
  int t[MAXN << 2];
  void upd(int p, int x, int v = 1, int tl = 0, int tr = MAXN) {
    if (tl == tr) {
      t[v] += x;
      return;
    }
    int tm = tl + tr >> 1;
    if (p <= tm) upd(p, x, v << 1, tl, tm);
    else upd(p, x, v << 1 | 1, tm +1 , tr);
    t[v] = t[v << 1] + t[v << 1 | 1];
  }
  int kth(int x, int v = 1, int tl = 0, int tr = MAXN) {
    if (tl == tr) return tl;
    int tm = tl + tr >> 1;
    if (t[v << 1] >= x) return kth(x, v << 1, tl, tm);
    return kth(x - t[v << 1], v << 1 | 1, tm + 1, tr);
  }
} T;

void Assist(unsigned char *A, int N, int K, int R) {
  int LOG = log2(K);
  set <int> st;
  rep(i, 0, K - 1) {
    st.insert(i);
    T.upd(i, 1);
  }
  for (int i = 0; i < R; ) {
    int add = GetRequest();
    if (A[i] == 0) {
      i++;
      continue;
    }
    else {
      i++;
      int id = 0;
      rep(j, 0, LOG) {
        if (A[i + j] == 1) id |= 1 << j;
      }
      int val = T.kth(id + 1);
      i += LOG + 1;
      // cerr << val << " -> " << endl;
      PutBack(val);
      T.upd(val, -1);
      st.erase(val);
    }
    st.insert(add);
    T.upd(add, 1);
  }
}

Compilation message

advisor.cpp: In member function 'void tree::upd(int, int, int, int, int)':
advisor.cpp:27:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int tm = tl + tr >> 1;
              ~~~^~~~
advisor.cpp: In member function 'int tree::get(int, int, int, int, int)':
advisor.cpp:35:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int tm = tl + tr >> 1;
              ~~~^~~~
advisor.cpp: In member function 'int tree::kth(int, int, int, int)':
advisor.cpp:40:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int tm = tl + tr >> 1;
              ~~~^~~~

assistant.cpp: In member function 'void fenwick::upd(int, int, int, int, int)':
assistant.cpp:26:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int tm = tl + tr >> 1;
              ~~~^~~~
assistant.cpp: In member function 'int fenwick::kth(int, int, int, int)':
assistant.cpp:33:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int tm = tl + tr >> 1;
              ~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 9968 KB Output is correct
2 Correct 8 ms 10224 KB Output is correct
3 Correct 9 ms 10480 KB Output is correct
4 Correct 14 ms 10736 KB Output is correct
5 Correct 17 ms 10736 KB Output is correct
6 Correct 24 ms 10992 KB Output is correct
7 Correct 14 ms 10992 KB Output is correct
8 Correct 25 ms 11248 KB Output is correct
9 Correct 26 ms 11248 KB Output is correct
10 Correct 22 ms 11248 KB Output is correct
11 Correct 23 ms 10992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 12000 KB Output is correct
2 Correct 166 ms 18672 KB Output is correct
3 Correct 526 ms 34048 KB Output is correct
4 Correct 355 ms 25840 KB Output is correct
5 Correct 440 ms 28144 KB Output is correct
6 Correct 472 ms 28912 KB Output is correct
7 Correct 457 ms 30832 KB Output is correct
8 Correct 430 ms 30448 KB Output is correct
9 Correct 277 ms 26096 KB Output is correct
10 Correct 438 ms 32000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 352 ms 26768 KB Output is correct
2 Correct 456 ms 31024 KB Output is correct
3 Correct 439 ms 31472 KB Output is correct
4 Correct 418 ms 30960 KB Output is correct
5 Correct 341 ms 29424 KB Output is correct
6 Correct 500 ms 31216 KB Output is correct
7 Correct 431 ms 31216 KB Output is correct
8 Correct 518 ms 33432 KB Output is correct
9 Correct 295 ms 30704 KB Output is correct
10 Correct 443 ms 31400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 10736 KB Error - advice is too long
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 450 ms 30192 KB Output is partially correct - 872365 bits used
2 Partially correct 448 ms 30128 KB Output is partially correct - 842095 bits used
3 Partially correct 443 ms 30824 KB Output is partially correct - 812470 bits used
4 Partially correct 437 ms 30680 KB Output is partially correct - 812005 bits used
5 Partially correct 440 ms 30736 KB Output is partially correct - 810610 bits used
6 Partially correct 457 ms 30648 KB Output is partially correct - 812155 bits used
7 Partially correct 450 ms 30648 KB Output is partially correct - 810929 bits used
8 Partially correct 442 ms 30808 KB Output is partially correct - 813340 bits used
9 Partially correct 450 ms 30704 KB Output is partially correct - 812830 bits used
10 Partially correct 528 ms 33096 KB Output is partially correct - 1217620 bits used