Submission #508658

# Submission time Handle Problem Language Result Execution time Memory
508658 2022-01-13T13:52:20 Z Abrar_Al_Samit Secret (JOI14_secret) C++17
100 / 100
512 ms 4404 KB
#include "secret.h"
#include <bits/stdc++.h>
const int MX = 1001;
int tab[13][MX];
int mask[MX];
int n, a[MX];
void prepare(int l, int r, int level) {
  if(l==r) return;
  int m = (l+r)/2;
  tab[level][m] = a[m];
  tab[level][m+1] = a[m+1];
  for(int i=m-1; i>=l; --i) {
    tab[level][i] = Secret(a[i], tab[level][i+1]);
  }
  for(int i=m+2; i<=r; ++i) {
    tab[level][i] = Secret(tab[level][i-1], a[i]);
  }
  for(int i=m+1; i<=r; ++i) {
    mask[i] ^= 1<<level;
  }
  prepare(l, m, level+1);
  prepare(m+1, r, level+1);
}
void Init(int N, int A[]) {
  n = N;
  for(int i=0; i<n; ++i) {
    a[i] = A[i];
  }
  prepare(0, n-1, 0);
}

int Query(int L, int R) {
  if(L==R) return a[L];
  int level = __builtin_ctz(mask[L]^mask[R]);
  return Secret(tab[level][L], tab[level][R]);
}
# Verdict Execution time Memory Grader output
1 Correct 136 ms 2376 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 134 ms 2484 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 124 ms 2388 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 495 ms 4292 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 500 ms 4228 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 512 ms 4260 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 476 ms 4292 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 483 ms 4320 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 454 ms 4404 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 460 ms 4316 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1