Submission #362975

# Submission time Handle Problem Language Result Execution time Memory
362975 2021-02-05T01:56:02 Z casperwang Last supper (IOI12_supper) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "advisor.h"
#define pb emplace_back
#define pii pair<int,int>
#define ff first
#define ss second
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }

const int MAXN = 100000;
const int P = 17;
vector <int> nxt[MAXN+1];
vector <int> cur;
vector <int> pos;
vector <bool> inseg;

class Seg {
private:
  pii arr[MAXN*4+5];
  void pull(int now) {
    arr[now] = max(arr[now*2], arr[now*2+1]);
  }
public:
  void build(int now, int l, int r) {
    if (l == r) {
      arr[now] = pii(*nxt[l].begin(), l);
      return;
    }
    int mid = l + r >> 1;
    build(now*2  , l, mid);
    build(now*2+1,mid+1,r);
    pull(now);
    return;
  }
  void mdy(int p, int id, int now, int l, int r) {
    if (l == p && r == p) {
      arr[now] = pii(nxt[id][cur[id]], l);
      return;
    } else if (l > p || r < p) return;
    int mid = l + r >> 1;
    mdy(p, id, now*2  , l, mid);
    mdy(p, id, now*2+1,mid+1,r);
    pull(now);
    return;
  }
  pii qry() {
    return arr[1];
  }
} seg;

void init(int *C, int N, int K, int M) {
  cur.resize(N);
  pos.resize(K);
  inseg.resize(K);
  for (int i = 0; i < N; i++) nxt[C[i]].pb(i);
  for (int i = 0; i < N; i++) nxt[i].pb(N);
  for (int i = 0; i < K; i++) inseg[i] = true;
  for (int i = 0; i < K; i++) pos[i] = i;
}

void Write(int num) {
  for (int i = 0; i < P; i++) {
    if ((1<<i) & num)
      WriteAdvice(1);
    else
      WriteAdvice(0);
  }
}

void ComputeAdvice(int *C, int N, int K, int M) {
  init(C, N, K, M);
  seg.build(1, 1, K-1);
  for (int i = 0; i < N; i++) {
    cur[C[i]]++;
    if (inseg[C[i]]) continue;
    auto [_t, p] = seg.qry();
    Write(pos[p]);
    pos[p] = C[i];
    seg.mdy(p, C[i], 1, 1, K-1);
  }
}
#include <bits/stdc++.h>
#include "assistant.h"
#define pb emplace_back
#define pii pair<int,int>
#define ff first
#define ss second
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }

const int MAXN = 100000;
const int P = 17;
vector <int> pos;
vector <bool> inseg;

void init(int N, int K, int M) {
  pos.resize(K);
  inseg.resize(K);
  for (int i = 0; i < K; i++) inseg[i] = true;
  for (int i = 0; i < K; i++) pos[i] = i;
}

int fnd(unsigned char *A, int a) {
  int st = a * P, num = 0;
  for (int i = st; i < st + P; i++) {
    if ((int)A[i]) num += (1<<(i-st));
  }
  return num;
}

void Assist(unsigned char *A, int N, int K, int R) {
  init(N, K, R);
  seg.build(1, 1, K-1);
  int now = 0;
  for (int i = 0; i < N; i++) {
    int req = GetRequest();
    if (!inseg[req]) {
      inseg[req] = true;
      PutBack(fnd(A, now++));
    }
  }
}

void init(int N, int K, int M) {
  pos.resize(K);
  inseg.resize(K);
  for (int i = 0; i < K; i++) inseg[i] = true;
  for (int i = 0; i < K; i++) pos[i] = i;
}

int fnd(unsigned char *A, int a) {
  int st = a * P, num = 0;
  for (int i = st; i < st + P; i++) {
    if ((int)A[i]) num += (1<<(i-st));
  }
  return num;
}

void Assist(unsigned char *A, int N, int K, int R) {
  init(N, K, R);
  seg.build(1, 1, K-1);
  int now = 0;
  for (int i = 0; i < N; i++) {
    int req = GetRequest();
    if (!inseg[req]) {
      inseg[req] = true;
      PutBack(fnd(A, now++));
    }
  }
}

Compilation message

advisor.cpp: In member function 'void Seg::build(int, int, int)':
advisor.cpp:32:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   32 |     int mid = l + r >> 1;
      |               ~~^~~
advisor.cpp: In member function 'void Seg::mdy(int, int, int, int, int)':
advisor.cpp:43:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   43 |     int mid = l + r >> 1;
      |               ~~^~~
advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:79:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   79 |     auto [_t, p] = seg.qry();
      |          ^

assistant.cpp: In function 'void Assist(unsigned char*, int, int, int)':
assistant.cpp:35:3: error: 'seg' was not declared in this scope; did you mean 'inseg'?
   35 |   seg.build(1, 1, K-1);
      |   ^~~
      |   inseg
assistant.cpp: At global scope:
assistant.cpp:46:6: error: redefinition of 'void init(int, int, int)'
   46 | void init(int N, int K, int M) {
      |      ^~~~
assistant.cpp:18:6: note: 'void init(int, int, int)' previously defined here
   18 | void init(int N, int K, int M) {
      |      ^~~~
assistant.cpp:53:5: error: redefinition of 'int fnd(unsigned char*, int)'
   53 | int fnd(unsigned char *A, int a) {
      |     ^~~
assistant.cpp:25:5: note: 'int fnd(unsigned char*, int)' previously defined here
   25 | int fnd(unsigned char *A, int a) {
      |     ^~~
assistant.cpp:61:6: error: redefinition of 'void Assist(unsigned char*, int, int, int)'
   61 | void Assist(unsigned char *A, int N, int K, int R) {
      |      ^~~~~~
assistant.cpp:33:6: note: 'void Assist(unsigned char*, int, int, int)' previously defined here
   33 | void Assist(unsigned char *A, int N, int K, int R) {
      |      ^~~~~~
assistant.cpp: In function 'void Assist(unsigned char*, int, int, int)':
assistant.cpp:63:3: error: 'seg' was not declared in this scope; did you mean 'inseg'?
   63 |   seg.build(1, 1, K-1);
      |   ^~~
      |   inseg