#include <bits/stdc++.h>
#include "secret.h"
using namespace std;
map<pair<int,int>,int> mp;
int a[1001];
void solve(int l,int r){
if(l==r)return;
int mid=(l+r)/2;
for(int i=mid-1;i>=l;i--){
mp[{i,mid}]=Secret(a[i],mp[{i+1,mid}]);
}
for(int i=mid+2;i<=r;i++){
mp[{mid+1,i}]=Secret(a[i],mp[{mid+1,i-1}]);
}
solve(l,mid-1);
solve(mid+1,r);
}
void Init(int N, int A[]) {
for(int i=0;i<N;i++){
a[i]=A[i];
mp[{i,i}]=a[i];
}
solve(0,N-1);
}
int Query(int L, int R) {
if(mp[{L,R}])return mp[{L,R}];
for(int i=L;i<R;i++){
if(mp[{L,i}] && mp[{i+1,R}])return Secret(mp[{L,i}],mp[{i+1,R}]);
}
return -1;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |