# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
747134 | Markomafko972 | 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 "secret.h"
int n;
int a[1005];
int val[1005][1005];
vector<int> v[1005];
int maxid = 0;
// 4: 0 1 2 3
void rek(int l, int r, int d) {
maxid = max(maxid, d);
if (l+1 == r) {
v[d].push_back(l);
val[l][l] = a[l];
return;
}
int mid = (l+r)/2;
int tren = a[mid-1];
for (int j = mid-2; j >= l; j--) {
tren = Secret(tren, a[j]);
val[j][mid-1] = tren;
}
tren = a[mid];
for (int j = mid+1; j < r; j++) {
tren = Secret(tren, a[j]);
val[mid][j] = tren;
}
v[d].push_back(mid);
rek(l, mid, d+1);
rek(mid, r, d+1);
}
void Init(int N, int A[]) {
n = N;
for (int i = 0; i < n; i++) a[i] = A[i];
rek(0, n, 0);
}
int Query(int l, int r) {
for (int i = 0; i <= maxid; i++) {
for (int j = 0; j < v[i].size(); j++) {
if (l <= v[i][j] && v[i][j] <= r) {
return Secret(val[l][val[i][j]-1], val[v[i][j]][r]);
}
}
}
}