답안 #125080

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
125080 2019-07-04T14:35:38 Z RockyB 최후의 만찬 (IOI12_supper) C++17
43 / 100
540 ms 32960 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])) {
      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;
    
    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);
  }
  int i = 0;
  for (int z = 0; z < N; z++) {
    int add = GetRequest();
    if (st.count(add)) {
      continue;
    }
    else {
      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;
              ~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 10224 KB Output is correct
2 Correct 8 ms 10224 KB Output is correct
3 Correct 9 ms 10424 KB Output is correct
4 Correct 14 ms 10480 KB Output is correct
5 Correct 16 ms 10736 KB Output is correct
6 Correct 23 ms 10736 KB Output is correct
7 Correct 14 ms 10784 KB Output is correct
8 Correct 24 ms 11248 KB Output is correct
9 Correct 26 ms 10936 KB Output is correct
10 Correct 22 ms 11248 KB Output is correct
11 Correct 22 ms 10992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 12016 KB Output is correct
2 Correct 162 ms 18656 KB Output is correct
3 Correct 536 ms 32960 KB Output is correct
4 Correct 362 ms 24304 KB Output is correct
5 Correct 426 ms 26352 KB Output is correct
6 Correct 471 ms 27392 KB Output is correct
7 Correct 469 ms 29192 KB Output is correct
8 Correct 432 ms 29168 KB Output is correct
9 Correct 263 ms 24560 KB Output is correct
10 Correct 454 ms 30512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 349 ms 25584 KB Output is correct
2 Correct 451 ms 29592 KB Output is correct
3 Correct 459 ms 29944 KB Output is correct
4 Correct 424 ms 29424 KB Output is correct
5 Correct 347 ms 28032 KB Output is correct
6 Correct 456 ms 29936 KB Output is correct
7 Correct 434 ms 29680 KB Output is correct
8 Correct 527 ms 32048 KB Output is correct
9 Correct 289 ms 29168 KB Output is correct
10 Correct 446 ms 29872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 10736 KB Error - advice is too long
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 474 ms 28912 KB Output is partially correct - 772365 bits used
2 Partially correct 447 ms 29480 KB Output is partially correct - 742095 bits used
3 Partially correct 449 ms 29424 KB Output is partially correct - 712470 bits used
4 Partially correct 452 ms 29680 KB Output is partially correct - 712005 bits used
5 Partially correct 453 ms 29424 KB Output is partially correct - 710610 bits used
6 Partially correct 456 ms 29424 KB Output is partially correct - 712155 bits used
7 Partially correct 459 ms 29368 KB Output is partially correct - 711090 bits used
8 Partially correct 449 ms 29680 KB Output is partially correct - 713340 bits used
9 Partially correct 453 ms 29672 KB Output is partially correct - 712830 bits used
10 Partially correct 540 ms 31728 KB Output is partially correct - 1117620 bits used