# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
714472 | MattTheNub | Secret (JOI14_secret) | C++17 | 459 ms | 4532 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"
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(a[i], dat[depth][i - 1]);
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 |
---|---|---|---|---|
Fetching results... |