# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
508651 | Abrar_Al_Samit | Secret (JOI14_secret) | C++17 | 472 ms | 4396 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 "secret.h"
#include <bits/stdc++.h>
const int MX = 1001;
int tab[10][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];
for(int i=m-1; i>=l; --i) {
tab[level][i] = Secret(a[i], tab[level][i+1]);
}
for(int i=m+1; i<=r; ++i) {
tab[level][i] = Secret(a[i], tab[level][i-1]);
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 |
---|---|---|---|---|
Fetching results... |