# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
661523 | rxlfd314 | Secret (JOI14_secret) | C++17 | 455 ms | 8388 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 <bits/stdc++.h>
#include "secret.h"
using namespace std;
constexpr int mxN = 1005;
int N, A[mxN], pref[mxN][mxN];
void precompute(int l, int r) {
if (l == r) return;
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]);
}
precompute(l, mid);
precompute(mid + 1, r);
}
void Init(int n, int* a) {
N = n;
for (int i = 0; i < N; i++) {
A[i] = a[i];
}
precompute(0, N - 1);
}
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... |