# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
134318 | someone_aa | Secret (JOI14_secret) | C++17 | 599 ms | 12720 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;
const int maxn = 1100;
int prefix[maxn][maxn];
int suffix[maxn][maxn];
int arr[maxn], n;
void precompute(int l, int r) {
if(l == r) prefix[l][l] = suffix[l][l] = arr[l];
else {
int mid = (l + r) / 2;
prefix[mid][mid] = suffix[mid][mid] = arr[mid];
for(int i=mid-1;i>=l;i--) {
suffix[mid][i] = Secret(arr[i], suffix[mid][i+1]);
}
for(int i=mid+1;i<=r;i++) {
prefix[mid][i] = Secret(prefix[mid][i-1], arr[i]);
}
precompute(l, mid);
precompute(mid+1,r);
}
}
void Init(int N, int A[]) {
n = N;
for(int i=0;i<n;i++) {
arr[i] = A[i];
}
precompute(0, n-1);
}
int solve(int ql, int qr, int li=0, int ri=n-1) {
if(li == ri) return arr[li];
else {
int mid = (li + ri) / 2;
if(ql <= mid && qr > mid) {
//cout<<ql<<", "<<qr<<" mid point: "<<mid<<"Here: ["<<li<<", "<<ri<<"]\n";
return Secret(suffix[mid][ql], prefix[mid][qr]);
}
else if(qr <= mid) {
return solve(ql, qr, li, mid);
}
else {
return solve(ql, qr, mid+1, ri);
}
}
}
int Query(int L, int R) {
return solve(L, R);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |