# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
599696 | stevancv | Secret (JOI14_secret) | C++14 | 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>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 1e3 + 2;
struct block {
int m;
vector<int> a, b;
};
int a[N];
vector<block> all;
void Init(int n, int A[]) {
for (int i = 0; i < n; i++) a[i] = A[i];
function<void(int, int)> DQ = [&] (int l, int r) {
if (l >= r) return;
block tr;
int mid = l + r >> 1;
tr.m = mid;
tr.a.push_back(a[mid]);
for (int i = mid - 1; i >= l; i--) {
tr.a.push_back(Secret(a[i], tr.a.back()));
}
tr.b.push_back(a[mid + 1]);
for (int i = mid + 2; i <= r; i++) {
tr.b.push_back(Secret(tr.b.back(), a[i]));
}
all.push_back(tr);
DQ(l, mid - 1);
DQ(mid + 2, r);
};
DQ(0, n - 1);
}
int Query(int l, int r) {
if (l == r) return a[l];
for (auto xyz : all) {
int m = xyz.m;
vector<int> a = xyz.a;
vector<int> b = xyz.b;
if (l <= m && m <= r) {
int x = 0; if (m - l < a.size()) x = a[m - l];
int y = 0; if (r - m - 1 < b.size() && r - m - 1 >= 0) y = b[r - m - 1];
return Secret(x, y);
}
}
}