Submission #714475

# Submission time Handle Problem Language Result Execution time Memory
714475 2023-03-24T15:26:58 Z MattTheNub Secret (JOI14_secret) C++17
100 / 100
470 ms 4332 KB
#include "secret.h"

int *a;
int dat[18][1005]{0};
int mask[1005]{0};

void compute(int l, int r, int depth) {
  if (l == r)
    return;

  int mid = (l + r) / 2;
  dat[depth][mid] = a[mid];
  for (int i = mid - 1; i >= l; i--)
    dat[depth][i] = Secret(a[i], dat[depth][i + 1]);
  dat[depth][mid + 1] = a[mid + 1];
  for (int i = mid + 2; i <= r; i++)
    dat[depth][i] = Secret(dat[depth][i - 1], a[i]);
  for (int i = mid + 1; i <= r; i++) {
    mask[i] ^= 1 << depth;
  }
  compute(l, mid, depth + 1);
  compute(mid + 1, r, depth + 1);
}

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

int Query(int L, int R) {
  if (L == R)
    return a[L];

  int x = __builtin_ctz(mask[L] ^ mask[R]);
  return Secret(dat[x][L], dat[x][R]);
}
# Verdict Execution time Memory Grader output
1 Correct 119 ms 2508 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 129 ms 2400 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 132 ms 2296 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 458 ms 4252 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 457 ms 4332 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 445 ms 4256 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 470 ms 4280 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 438 ms 4272 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 462 ms 4272 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 461 ms 4268 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1