# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
284205 | ChrisT | Secret (JOI14_secret) | C++17 | 517 ms | 8696 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>
#include "secret.h"
using namespace std;
const int MN = 1e3 + 5;
int pre[MN][MN], suf[MN][MN], a[MN], n, ops;
void Init (int N, int *arr) {
n=N;
for (int i = 0; i < n; i++) a[i] = arr[i];
function<void(int,int)> build = [&] (int l, int r) {
if (l>=r) return;
int mid = (l + r + 1) / 2;
pre[mid][mid] = a[mid];
suf[mid][mid-1] = a[mid-1];
for (int i = mid+1; i <= r; i++) pre[mid][i] = Secret(pre[mid][i-1],a[i]);
for (int i = mid-2; i >= l; i--) suf[mid][i] = Secret(a[i],suf[mid][i+1]);
build(l,mid-1); build(mid+1,r);
};
build(0,n-1);
}
int query (int l, int r, int ql, int qr) {
int mid = (l + r + 1) / 2;
if (qr < mid - 1) return query(l,mid-1,ql,qr);
if (ql > mid) return query(mid+1,r,ql,qr);
if (ql == mid) return pre[mid][qr];
if (qr == mid-1) return suf[mid][ql];
return Secret(suf[mid][ql],pre[mid][qr]);
}
int Query (int L, int R) {
if (L == R) return a[L];
return query(0,n-1,L,R);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |