bdfz_2024_summer/day5/perfect/fix.cpp

67 lines
1.5 KiB
C++
Raw Normal View History

2024-08-08 06:12:15 +00:00
#include<bits/stdc++.h>
using namespace std;
2024-08-09 09:12:44 +00:00
#define int long long
2024-08-09 15:03:07 +00:00
#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];
2024-08-08 06:12:15 +00:00
2024-08-09 15:03:07 +00:00
int read();
int pow2(int n){return 1<<n;}
2024-08-08 06:12:15 +00:00
2024-08-09 15:03:07 +00:00
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;
2024-08-08 06:12:15 +00:00
for(int i=1;i<=n;i++){
2024-08-09 15:03:07 +00:00
if(i>1)l[i]=l[i/2]+1;
smin[i][0]=smax[i][0]=read();
2024-08-08 15:43:59 +00:00
}
2024-08-09 15:03:07 +00:00
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];
2024-08-09 09:12:44 +00:00
ans=max(
2024-08-09 15:03:07 +00:00
ans,
(min(smin[i][k],smin[j-(pow2(k)+1)][k])
^
max(smax[i][k],smax[j-pow2(k)+1][k]))
2024-08-09 09:12:44 +00:00
);
2024-08-08 06:12:15 +00:00
}
}
2024-08-08 15:43:59 +00:00
cout<<ans<<endl;
2024-08-09 15:03:07 +00:00
#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;
2024-08-08 06:12:15 +00:00
}