Submission #540766

#TimeUsernameProblemLanguageResultExecution timeMemory
540766HazemSecret (JOI14_secret)C++14
0 / 100
515 ms8232 KiB
#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 timeMemoryGrader output
Fetching results...