Submission #538902

# Submission time Handle Problem Language Result Execution time Memory
538902 2022-03-18T02:12:38 Z schiftyfive4 Secret (JOI14_secret) C++14
100 / 100
451 ms 4448 KB
#include <bits/stdc++.h>
#include "secret.h"
using namespace std;

int n;
vector<vector<int>> t(15, vector<int>(1005));

void calc(int L, int R, int dep, int A[]) {
  assert(dep < 15);
  if (L == R) {
    t[dep][L] = A[L];
    return;
  }
  int m = (L + R) / 2;
  t[dep][m] = A[m];
  for (int i = m - 1; i >= L; i--) {
    t[dep][i] = Secret(A[i], t[dep][i + 1]);
  }
  t[dep][m + 1] = A[m + 1];
  for (int i = m + 2; i <= R; i++) {
    t[dep][i] = Secret(t[dep][i - 1], A[i]);
  }
  calc(L, m, dep + 1, A);
  calc(m + 1, R, dep + 1, A);
}

void Init(int N, int A[]) {
  n = N;
  calc(0, n - 1, 0, A);
}

int get(int L, int R, int qL, int qR, int dep) {
  assert(dep < 15);
  assert(L <= qL && qR <= R);
  if (L == R) {
    return t[dep][L];
  }
  int m = (L + R) / 2;
  if (qL <= m && m + 1 <= qR) {
    return Secret(t[dep][qL], t[dep][qR]);
  } else if (qR <= m) {
    return get(L, m, qL, qR, dep + 1);
  }
  return get(m + 1, R, qL, qR, dep + 1);
}

int Query(int L, int R) {
  return get(0, n - 1, L, R, 0);
}
# Verdict Execution time Memory Grader output
1 Correct 124 ms 2408 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 122 ms 2352 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 123 ms 2400 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 438 ms 4296 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 451 ms 4264 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 431 ms 4268 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 433 ms 4368 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 433 ms 4260 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 434 ms 4416 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 432 ms 4448 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1