Submission #752588

#TimeUsernameProblemLanguageResultExecution timeMemory
752588jamezzzSecret (JOI14_secret)C++17
0 / 100
446 ms8696 KiB
#include "secret.h" #include <bits/stdc++.h> using namespace std; #define pf printf int n,a[1024],st[12][1024]; inline int ask(int x,int y){ if(x==-1)return y; if(y==-1)return x; return Secret(x,y); } void build(int lvl,int l,int r){ int m=(l+r)>>1; int pv=-1; for(int i=m;i>=l;--i){ pv=st[lvl][i]=ask(a[i],pv); } pv=-1; for(int i=m+1;i<=r;++i){ pv=st[lvl][i]=ask(pv,a[i]); } if(l==r)return; build(lvl-1,l,m); build(lvl-1,m+1,r); } void Init(int N,int A[]){ n=N; for(int i=0;i<n;++i)a[i]=A[i]; int lvl=31-__builtin_clz(n); int sz=n; if((1<<lvl)!=n)++lvl,sz=1<<lvl; for(int i=n;i<sz;++i)a[i]=-1; build(lvl-1,0,sz-1); } int Query(int L,int R){ int lvl=31-__builtin_clz(L^R); return L==R?st[lvl][L]:ask(st[lvl][L],st[lvl][R]); }
#Verdict Execution timeMemoryGrader output
Fetching results...