# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
774488 | colossal_pepe | Secret (JOI14_secret) | C++17 | 365 ms | 12328 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"
#include <vector>
using namespace std;
int n;
vector<vector<int>> tree(4005);
void buildTree(int node, int l, int r, int a[]) {
tree[node].resize(n);
if (node % 2) {
tree[node][l] = a[l];
for (int i = l + 1; i <= r; i++) {
tree[node][i] = Secret(tree[node][i - 1], a[i]);
}
} else {
tree[node][r] = a[r];
for (int i = r - 1; i >= l; i--) {
tree[node][i] = Secret(a[i], tree[node][i + 1]);
}
}
if (l != r) {
int mid = (l + r) / 2;
buildTree(2 * node, l, mid, a);
buildTree(2 * node + 1, mid + 1, r, a);
}
}
int query(int node, int l, int r, int L, int R) {
if (l == r) return tree[node][l];
int mid = (l + r) / 2;
if (R <= mid) return query(2 * node, l, mid, L, R);
else if (L > mid) return query(2 * node + 1, mid + 1, r, L, R);
else return Secret(tree[2 * node][L], tree[2 * node + 1][R]);
}
void Init(int N, int A[]) {
n = N;
buildTree(2, 0, (n - 1) / 2, A);
buildTree(3, ((n - 1) / 2) + 1, n - 1, A);
}
int Query(int L, int R) {
return query(1, 0, n - 1, L, R);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |