| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 1012900 | Tob | Last supper (IOI12_supper) | C++14 | 0 ms | 0 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pb push_back
#define FIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pii;
#include "advisor.h"
#include "assistant.h"
/*
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#define inbuf_len 1 << 16
#define outbuf_len 1 << 16
void ComputeAdvice(int *C, int N, int K, int M);
void Assist(unsigned char *A, int N, int K, int R);
static int N, K, M;
static int *C;
static int R;
static unsigned char *A;
static FILE *fadvice;
static int current_request = -1;
static int *in_scaffold;
static int expect_put_back;
int GetRequest(void) {
  int req;
  if (expect_put_back) {
    fprintf(stderr, "Not putting back color when it is not on the scaffold\n");
    exit(1);
  }
  req = C[++current_request];
  if (!in_scaffold[req])
    expect_put_back = TRUE;
  else
    expect_put_back = FALSE;
  printf("R %d\n", req);
  return req;
}
void PutBack(int T) {
  int req;
  if (!expect_put_back) {
    fprintf(stderr, "Putting back a color when it is already on the scaffold\n");
    exit(1);
  }
  if (!in_scaffold[T]) {
    fprintf(stderr, "Putting back a color that is not on the scaffold\n");
    exit(1);
  }
  req = C[current_request];
  in_scaffold[req] = TRUE;
  in_scaffold[T] = FALSE;
  expect_put_back = FALSE;
  printf("P %d\n", T);
}
void WriteAdvice(unsigned char a) {
  a = !!a;
  if (R < M) {
    fprintf(fadvice, "%hhu ", a);
    A[R] = a;
    R++;
  } else {
    fprintf(stderr, "Advisor is providing too many bits of advice\n");
    exit(1);
  };
}
static inline void input_assert(int ok) {
  if (!ok) {
    fprintf(stderr, "Invalid input file.\n");
    exit(1);
  }
}*/
//------------------------------------------------------------------
// No communication/shared data between two namespaces 
namespace advisor {
void ComputeAdvice(int *c, int n, int k, int m) {
	vector <vector <int> > ne(n), del(n);
	for (int i = 0; i < n; i++) {
		ne[c[i]].pb(i);
	}
	for (int i = 0; i < n; i++) ne[i].pb(n);
	set <pii> s;
	for (int i = 0; i < k; i++) s.insert({*ne[i].begin(), i});
	for (int i = 0; i < n; i++) {
		int x = c[i];
		if (s.find({i, x}) != s.end()) s.erase({i, x});
		else {
			int y = (--s.end()) -> S;
			s.erase(--s.end());
			del[y].pb(i);
		}
		s.insert({*upper_bound(all(ne[x]), i), x});
	}
	vector <int> res(n+k, 0);
	for (int i = 0; i < n; i++) del[i].pb(n+1);
	for (int i = 0; i < k; i++) {
		res[i] = (*del[i].begin() > *ne[i].begin());
	}
	for (int i = 0; i < n; i++) {
		res[k+i] = (*upper_bound(all(del[c[i]]), i) > *upper_bound(all(ne[c[i]]), i));
	}
	for (int i = 0; i < n+k; i++) {
		WriteAdvice(res[i]);
	}
}
} // namespace advisor
namespace assistant {
void Assist(unsigned char *a, int n, int k, int r) {
	set <int> s, t;
	for (int i = 0; i < k; i++) {
		s.insert(i);
		if (!a[i]) t.insert(i);
	}
	for (int i = 0; i < n; i++) {
		int x = GetRequest();
		if (s.find(x) == s.end()) {
			int y = *t.begin();
			s.erase(y);
			t.erase(y);
			s.insert(x);
			PutBack(y);
		}
		if (!a[k+i]) t.insert(x);
	}
}
} // namespace assitant
// Called by grader, do not modify
void Assist(unsigned char *A, int N, int K, int R) {
  assistant::Assist(A, N, K, R);
}
void ComputeAdvice(int *C, int N, int K, int M) {
  advisor::ComputeAdvice(C, N, K, M);
}
//----------------------------------------------------------------
/*
int main() {
  int tmp;
  int i;
  char *inbuf, *outbuf;
  inbuf = (char*) malloc(inbuf_len * sizeof(char));
  outbuf = (char*) malloc(outbuf_len * sizeof(char));
  tmp = setvbuf(stdin, inbuf, _IOFBF, inbuf_len);
  tmp = setvbuf(stdout, outbuf, _IOFBF, outbuf_len);
  fadvice = fopen("advice.txt", "w");
  tmp = scanf("%d %d %d", &N, &K, &M);
  input_assert(tmp == 3);
  C = (int*) malloc(N * sizeof(int));
  for (i = 0; i < N; i++) {
    tmp = scanf("%d", &C[i]);
    input_assert(tmp == 1);
  }
  A = (unsigned char*) malloc(M * sizeof(int));
  ComputeAdvice(C, N, K, M);
  fprintf(fadvice, "\n2\n");
  in_scaffold = (int*) malloc(N * sizeof(int));
  for (i = 0; i < K; i++)
    in_scaffold[i] = TRUE;
  for (i = K; i < N; i++)
    in_scaffold[i] = FALSE;
  Assist(A, N, K, R);
  printf("E\n");
  return 0;
}*/
