# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
538902 | schiftyfive4 | Secret (JOI14_secret) | C++14 | 451 ms | 4448 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;
int n;
vector<vector<int>> t(15, vector<int>(1005));
void calc(int L, int R, int dep, int A[]) {
assert(dep < 15);
if (L == R) {
t[dep][L] = A[L];
return;
}
int m = (L + R) / 2;
t[dep][m] = A[m];
for (int i = m - 1; i >= L; i--) {
t[dep][i] = Secret(A[i], t[dep][i + 1]);
}
t[dep][m + 1] = A[m + 1];
for (int i = m + 2; i <= R; i++) {
t[dep][i] = Secret(t[dep][i - 1], A[i]);
}
calc(L, m, dep + 1, A);
calc(m + 1, R, dep + 1, A);
}
void Init(int N, int A[]) {
n = N;
calc(0, n - 1, 0, A);
}
int get(int L, int R, int qL, int qR, int dep) {
assert(dep < 15);
assert(L <= qL && qR <= R);
if (L == R) {
return t[dep][L];
}
int m = (L + R) / 2;
if (qL <= m && m + 1 <= qR) {
return Secret(t[dep][qL], t[dep][qR]);
} else if (qR <= m) {
return get(L, m, qL, qR, dep + 1);
}
return get(m + 1, R, qL, qR, dep + 1);
}
int Query(int L, int R) {
return get(0, n - 1, L, R, 0);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |