Submission #525553

#TimeUsernameProblemLanguageResultExecution timeMemory
525553omohamadoooSecret (JOI14_secret)C++14
100 / 100
467 ms12332 KiB
#include "secret.h" #include "bits/stdc++.h" #define ll long long using namespace std; int n; int v[1005]; int pref[4005][1005],suff[4005][1005]; int ask(int a, int b){ return Secret(a, b); } void build(ll lx,ll rx,int x) { if(lx == rx) return; ll m = (lx + rx)/2; pref[x][m] = v[m]; for(int p=m-1;p>=lx;p--){ pref[x][p] = ask(v[p], pref[x][p+1] ); } suff[x][m+1] = v[m+1]; for(int p=m+2;p<=rx;p++){ suff[x][p] = ask(suff[x][p-1], v[p]); } build(lx, m, x*2+1); build(m+1, rx, x*2+2); } void Init(int f , int a[]) { n = f; for(ll i=0;i<n;i++) v[i] = a[i]; build(0,n-1,0); } int get(int l, int r, int lx, int rx, int x){ if(lx == rx) return v[lx]; int m = (lx + rx) >> 1; if(r <= m) return get(l, r, lx, m, x*2+1); if(m < l) return get(l, r, m+1, rx, x*2+2); return ask(pref[x][l], suff[x][r]); } int Query(int l, int r) { return get(l,r , 0,n-1,0); }
#Verdict Execution timeMemoryGrader output
Fetching results...