XOR-pyramid
XOR-pyramid
https://ac.nowcoder.com/acm/problem/112798
#include <bits/stdc++.h> using namespace std; const int maxn=5009; int a[maxn],n,dp[maxn][maxn],f[maxn][maxn]; int main() { cin >> n; for(int i=1;i<=n;i++) cin >> a[i],dp[i][i]=a[i],f[i][i]=a[i]; for(int i=1;i<n;i++) { dp[i][i+1]=a[i]^a[i+1]; f[i][i+1]=max( f[i][i],f[i+1][i+1] ); f[i][i+1]=max( f[i][i+1],dp[i][i+1] ); } for(int l=3;l<=n;l++) for(int i=1;i+l-1<=n;i++) { int j=i+l-1; dp[i][j] = (dp[i][j-1]^dp[i+1][j] ); f[i][j]=max(f[i][j-1],f[i+1][j] ); f[i][j]=max( f[i][j],dp[i][j] ); } int q; cin >> q; while( q-- ) { int l,r; cin >>l >> r; cout << f[l][r] << '\n'; } }