# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
793470 | asdfgrace | Secret (JOI14_secret) | C++17 | 0 ms | 0 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>
using namespace std;
int n;
vector<int> a;
vector<vector<int>> lef, rig;
void Init(int N, int A[]) {
n = N;
a.resize(N);
for (int i = 0; i < N; ++i) a[i] = A[i];
lef.resize(N); rig.resize(N);
queue<pair<int, int>> q;
q.push({0, n - 1});
while (!q.empty()) {
int l = q.front().first, r = q.front().second;
q.pop();
int m = (l + r) / 2;
lef[m].push_back(A[m]);
for (int i = 1; i <= (m - l); ++i) {
lef[m].push_back(Secret(A[m - i], lef[m].back()));
}
if (m + 1 < N) {
rig[m].push_back(A[m + 1]);
for (int i = 2; i <= (r - m); ++i) {
rig[m].push_back(Secret(rig[m].back(), A[m + i]));
}
}
if (l == r) continue;
q.push({l, m});
q.push({m + 1, r});
}
}
int Query(int L, int R) {
if (L == R) return a[L];
int l = 0, r = n - 1;
while (true) {
int m = (l + r) / 2;
if (R <= m) {
r = m;
} else if (L > m) {
l = m + 1;
} else {
return Secret(lef[m][m - L], rig[m][R - m - 1]);
}
}
}