# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
21129 | sbansalcs | Secret (JOI14_secret) | C++14 | 619 ms | 12956 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"
int val[1002][1002], hav[1002][1002], X[1002];
void comp(int a, int b) {
if(a>=b) return;
if(b-a==1) hav[a][b]=1,val[a][b]=Secret(X[a],X[b]);
int f=(a+b)/2,f2=f+1;
for(int i=f-1;i>=a;i--) hav[i][f]=1,val[i][f]=(i==f-1)?Secret(X[i],X[f]):Secret(X[i],val[i+1][f]);
for(int i=f+2;i<=b;i++) hav[f+1][i]=1,val[f+1][i]=(i==f+2)?Secret(X[f+1],X[i]):Secret(val[f+1][i-1],X[i]);
if(hav[f][f2]==0) hav[f][f2]=1,val[f][f2]=Secret(X[f],X[f2]);
comp(a,f-1),comp(f2+1,b);
}
void Init(int N, int A[]) {
for(int i=1;i<=N;i++) X[i]=A[i-1],hav[i][i]=1,val[i][i]=A[i-1];
comp(1,N);
}
int Query(int L, int R) {
if(hav[L+1][R+1]) return val[L+1][R+1];
for(int i=L+1;i<=R;i++) {
if(hav[L+1][i] && hav[i+1][R+1]) return Secret(val[L+1][i],val[i+1][R+1]);
}
return -1;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |