递推式:f[i,j]=f[i+1,j]^f[i,j-1]
#include<bits/stdc++.h>
using namespace std;
const int N=5010;
int a[N];
int f[N][N];
int dp[N][N];
int main(){
memset(f,0,sizeof f);
memset(dp,0,sizeof dp);
// freopen("in.txt","r",stdin);
int n;scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
f[i][i]=a[i];
dp[i][i]=a[i];
}
for(int len=2;len<=n;len++){
for(int i=1;i<=n;i++){
int j=i+len-1;
if(j>n) break;
f[i][j]=f[i+1][j]^f[i][j-1];
}
}
for(int len=2;len<=n;len++){
for(int i=1;i<=n;i++){
int j=i+len-1;
if(j>n) break;
dp[i][j]=max(f[i][j],max(dp[i+1][j],dp[i][j-1]));
}
}
int q;scanf("%d",&q);
while(q--){
int l,r;
scanf("%d%d",&l,&r);
printf("%d\n",dp[l][r]);
}
}