# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
704612 | dubabuba | Secret (JOI14_secret) | C++14 | 439 ms | 8372 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"
const int mxn = 1010;
int range[mxn][mxn];
int n, a[mxn];
int build(int l, int r, int a[]) {
if(l == r) return range[l][r] = a[l];
if(l == r - 1) return range[l][r] = Secret(a[l], a[r]);
build(l, (l + r) / 2, a);
build((l + r) / 2 + 1, r, a);
int m = (l + r) / 2;
range[m][m] = a[m];
for(int s = m - 1; s >= l; s--)
range[s][m] = Secret(a[s], range[s + 1][m]);
m++;
range[m][m] = a[m];
for(int e = m + 1; e <= r; e++)
range[m][e] = Secret(range[m][e - 1], a[e]);
return 0;
}
void Init(int N, int A[]) {
build(0, N - 1, A);
n = N;
}
int Query(int L, int R) {
int l = 0, r = n - 1;
while(r - l > 1) {
int m = (l + r) / 2;
if(L == m) return range[L][R];
if(R == m) return range[L][R];
if(L <= m && m < R) return Secret(range[L][m], range[m + 1][R]);
if(m < L) l = m;
else r = m + 1;
}
return range[L][R];
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |