# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
752588 | jamezzz | Secret (JOI14_secret) | C++17 | 446 ms | 8696 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>
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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |