# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
543095 | BERNARB01 | Secret (JOI14_secret) | C++17 | 458 ms | 12208 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 <bits/stdc++.h>
using namespace std;
int n, a[1003], tr[2003][1003];
void build(int x, int l, int r, int rig) {
if (l == r) {
tr[x][l] = a[l];
return;
}
int y = (l + r) >> 1;
int z = x + ((y - l + 1) << 1);
build(x + 1, l, y, 0);
build(z, y + 1, r, 1);
if (rig == -1) {
return;
}
if (rig) {
tr[x][l] = a[l];
for (int i = l + 1; i <= r; i++) {
tr[x][i] = Secret(tr[x][i - 1], a[i]);
}
} else {
tr[x][r] = a[r];
for (int i = r - 1; i >= l; i--) {
tr[x][i] = Secret(a[i], tr[x][i + 1]);
}
}
}
int get(int x, int l, int r, int ll, int rr) {
int y = (l + r) >> 1;
int z = x + ((y - l + 1) << 1);
if (rr <= y) {
return get(x + 1, l, y, ll, rr);
}
if (ll > y) {
return get(z, y + 1, r, ll, rr);
}
return Secret(tr[x + 1][ll], tr[z][rr]);
}
void Init(int N, int A[]) {
n = N;
for (int i = 0; i < n; i++) {
a[i] = A[i];
}
build(0, 0, n - 1, -1);
}
int Query(int l, int r) {
if (l == r) {
return a[l];
}
return get(0, 0, n - 1, l, r);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |