# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
661542 | rxlfd314 | Secret (JOI14_secret) | C++17 | 431 ms | 8164 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 n, pref[1000][1000];
void precompute(int l, int r, int A[]) {
int mid = l + r >> 1;
pref[mid][mid] = A[mid];
pref[mid+1][mid+1] = A[mid+1];
for (int i = mid - 1; i >= l; i--) {
pref[mid][i] = Secret(pref[mid][i+1], A[i]);
}
for (int i = mid + 2; i <= r; i++) {
pref[mid+1][i] = Secret(pref[mid+1][i-1], A[i]);
}
if (l < mid) {
precompute(l, mid, A);
}
if (mid + 1 < r) {
precompute(mid + 1, r, A);
}
}
void Init(int N, int A[]) {
n = N;
precompute(0, N - 1, A);
}
int Query(int L, int R) {
int lo = 0, hi = n - 1;
while (lo != hi) {
int mid = lo + hi >> 1;
if (L <= mid && mid < R) {
return Secret(pref[mid][L], pref[mid+1][R]);
}
if (R == mid) {
return pref[mid][L];
}
if (mid < L) {
lo = mid + 1;
} else {
hi = mid;
}
}
return pref[lo][lo];
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |