# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
365169 | Bill_00 | Secret (JOI14_secret) | C++14 | 535 ms | 8324 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;
int a[1001],n;
int ans[1001][1001];
void build(int l,int r){
if(l>r){
return;
}
if(l==r){
ans[l][r]=a[l];
return;
}
int m=(l+r)>>1;
int k=a[m];
ans[m][m]=a[m];
for(int i=m-1;i>=l;i--){
k=Secret(a[i],k);
ans[i][m]=k;
}
k=a[m+1];
ans[m+1][m+1]=a[m+1];
for(int i=m+2;i<=r;i++){
k=Secret(k,a[i]);
ans[m+1][i]=k;
}
build(l,m-1);
build(m+2,r);
}
int query(int l,int r,int L,int R){
int m=(l+r)>>1;
if(L<=m && m<=R){
if(m==R){
return ans[L][m];
}
else return Secret(ans[L][m],(m+1==R?a[R]:ans[m+1][R]));
}
if(L<=(m+1) && (m+1)<=R){
if(m+1==L){
return ans[m+1][R];
}
else return Secret((m==L?a[L]:ans[L][m]),ans[m+1][R]);
}
if(m>R){
return query(l,m-1,L,R);
}
else return query(m+2,r,L,R);
}
void Init(int N, int A[]){
n=N;
for(int i=0;i<n;i++) a[i]=A[i];
build(0,n-1);
}
int Query(int L, int R) {
if(L==R) return a[L];
return query(0,n-1,L,R);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |