#include "secret.h"
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
vector<int>a;
int n;
int st[5000];
int dp[5000][5000];
void build(int L, int R){
if(L==R){
dp[L][R]=a[L];
return;
}
int mid=(L+R)/2;
for(int i=mid-1;i>=L;i--){
dp[mid][i] = Secret(dp[mid][i+1],a[i]);
dp[i][mid]=dp[mid][i];
}
for(int i=mid+1;i<=R;i++){
dp[mid][i] = Secret(dp[mid][i-1],a[i]);
dp[i][mid]=dp[mid][i];
}
build(L,mid);
build(mid+1,R);
}
void Init(int N, int A[]) {
n=N;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++)dp[i][j]=-1;
}
a.clear();
a.pb(0);
for(int i=0;i<N;i++)a.push_back(A[i]);
build(1,n);
}
int Query(int L, int R) {
L++,R++;
if(dp[L][R]!=-1)return dp[L][R];
for(int i=1;i<=n;i++){
if(dp[L][i]!=-1 and dp[i+1][R]!=-1){
return Secret(dp[L][i],dp[i+1][R]);
}
}
}
Compilation message (stderr)
secret.cpp: In function 'int Query(int, int)':
secret.cpp:48:1: warning: control reaches end of non-void function [-Wreturn-type]
48 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |