67 lines
1.5 KiB
C++
67 lines
1.5 KiB
C++
#include<bits/stdc++.h>
|
|
using namespace std;
|
|
#define int long long
|
|
#define AS(c){if(!(c)){cout<<"assert failed: "<<#c<<endl;}}
|
|
const int MAX_N=5e5+5;
|
|
const int MAX_K=50;
|
|
int n,k,ans{0};
|
|
int smin[MAX_N][MAX_K],smax[MAX_N][MAX_K],l[MAX_N];
|
|
|
|
int read();
|
|
int pow2(int n){return 1<<n;}
|
|
|
|
signed main(signed argc,char *argv[]){
|
|
#ifdef OITEST
|
|
cout<<"TESTING"<<endl;
|
|
AS(argc==3)
|
|
auto f = freopen(argv[1],"r",stdin);
|
|
AS(f!=NULL)
|
|
ifstream afile(argv[2]);
|
|
AS(afile.is_open()==true)
|
|
int cans;
|
|
afile>>cans;
|
|
#endif
|
|
n=read();
|
|
// if(n>999){cout<<1048575<<endl;return 0;}
|
|
l[1]=0;
|
|
for(int i=1;i<=n;i++){
|
|
if(i>1)l[i]=l[i/2]+1;
|
|
smin[i][0]=smax[i][0]=read();
|
|
}
|
|
k=l[n]+1;
|
|
for(int j=1;j<=k;j++){
|
|
for(int i=1;i+(1<<j)-1<=n;i++){
|
|
smin[i][j]=min(smin[i][j-1],smin[i+pow2(j-1)][j-1]);
|
|
smax[i][j]=max(smax[i][j-1],smax[i+pow2(j-1)][j-1]);
|
|
}
|
|
}
|
|
for(int i=1;i<=n;i++){
|
|
for(int j=i;j<=n;j++){
|
|
int k=l[j-i+1];
|
|
ans=max(
|
|
ans,
|
|
(min(smin[i][k],smin[j-(pow2(k)+1)][k])
|
|
^
|
|
max(smax[i][k],smax[j-pow2(k)+1][k]))
|
|
);
|
|
}
|
|
}
|
|
cout<<ans<<endl;
|
|
#ifdef OITEST
|
|
AS(ans==cans)
|
|
#endif
|
|
}
|
|
|
|
int read(){
|
|
int x=0,w=1;
|
|
char ch=0;
|
|
while(!isdigit(ch)){
|
|
if(ch=='-')w=-1;
|
|
ch=getchar();
|
|
}
|
|
while(isdigit(ch)){
|
|
x=x*10+ch-'0';
|
|
ch=getchar();
|
|
}
|
|
return x*w;
|
|
} |