Submission #540770

#TimeUsernameProblemLanguageResultExecution timeMemory
540770HazemSecret (JOI14_secret)C++14
100 / 100
538 ms8260 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(a[i],ans[v][i+1]); 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) if(r==mid) return ans[v][l]; else 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+1]; return get(1,1,n,L+1,R+1); }

Compilation message (stderr)

secret.cpp: In function 'int get(int, int, int, int, int)':
secret.cpp:32:7: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   32 |     if(mid>=l&&mid<=r)
      |       ^
#Verdict Execution timeMemoryGrader output
Fetching results...