题意:
%EF%BC%8C%E7%84%B6%E5%90%8E%E6%9C%89q%E4%B8%AA%E8%AF%A2%E9%97%AE%EF%BC%8C%E6%AF%8F%E4%B8%AA%E8%AF%A2%E9%97%AE%20%5Bl%2Cr%5D%20%E6%B1%82%E6%9C%80%E5%A4%A7%E7%9A%84f(i%2Cj)%EF%BC%8C%E5%85%B6%E4%B8%AD1%3C%3Dl%3C%3Di%3C%3Dj%3C%3Dr&preview=true)
思路:




%20%3D%20f(i%2Cj%20-%201)%20xor%20f(i%2B1%2Cj)&preview=true)
%E8%A1%A8%E7%A4%BA%E5%8C%BA%E9%97%B4i%E5%88%B0j%E7%9A%84%E5%87%BD%E6%95%B0%E5%80%BC%EF%BC%8C%E5%86%8D%E5%AE%9A%E4%B9%89%E4%B8%80%E4%B8%AAmx(i%2Cj)%E4%B8%8D%E6%96%AD%E6%9B%B4%E6%96%B0%E6%9C%80%E5%A4%A7%E5%80%BC%EF%BC%8C%E9%95%BF%E5%BA%A6%E9%80%92%E5%A2%9E%E5%9C%B0%E5%8E%BB%E6%9B%B4%E6%96%B0&preview=true)
%20%3D%20max(f(i%2Cj)%2Cmx(i%2B1%2Cj)%2Cmx(i%2Cj-1))&preview=true)
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 5e3 + 10;
int n,f[N][N],mx[N][N];
int main(){
scanf("%d",&n);
for(int i = 1;i <= n;i++){
scanf("%d",&f[i][i]);
mx[i][i] = f[i][i];
}
for(int len = 2;len <= n;len++){
for(int i = 1,j;i + len - 1 <= n;i++){
j = i + len - 1;
mx[i][j] = f[i][j] = f[i][j - 1] ^ f[i + 1][j];
mx[i][j] = max(mx[i][j],max(mx[i][j - 1],mx[i + 1][j]));
}
}
int q;scanf("%d",&q);
while(q--){
int l,r;scanf("%d%d",&l,&r);
printf("%d\n",mx[l][r]);
}
return 0;
}