# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
540766 | Hazem | Secret (JOI14_secret) | C++14 | 515 ms | 8232 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>
const int M = 1e3+10;
int a[M],n;
int ans[4*M][M];
void build(int v,int tl,int tr){
if(tl==tr)
return ;
int mid = (tl+tr)/2;
ans[v][mid] = a[mid];
ans[v][mid+1] = a[mid+1];
for(int i=mid+2;i<=tr;i++)
ans[v][i] = Secret(ans[v][i-1],a[i]);
for(int i=mid-1;i>=tl;i--)
ans[v][i] = Secret(ans[v][i+1],a[i]);
build(v*2,tl,mid);
build(v*2+1,mid+1,tr);
}
int get(int v,int tl,int tr,int l,int r){
int mid = (tl+tr)/2;
if(mid>=l&&mid<=r)
return Secret(ans[v][l],ans[v][r]);
if(r<=mid)
return get(v*2,tl,mid,l,r);
else
return get(v*2+1,mid+1,tr,l,r);
}
void Init(int N, int A[]) {
for(int i=0;i<N;i++)
a[i+1] = A[i];
n = N;
build(1,1,N);
}
int Query(int L, int R) {
if(L==R)
return a[L];
return get(1,1,n,L+1,R+1);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |