This commit is contained in:
Zengtudor 2024-08-08 23:43:59 +08:00
parent 2c21d5896a
commit 35d4a9ea27
2 changed files with 52 additions and 6 deletions

View File

@ -5,24 +5,66 @@ const int MAX_N = 3e5+5;
const int MAX_K = 19;
int sMin[MAX_N][MAX_K];
int sMax[MAX_N][MAX_K];
int l[MAX_N];
int l2[MAX_N];
int main(){
#ifndef OITEST
#define PRINT_VALUE(v)
#endif
int main(int argc,char* argv[]){
#ifdef OITEST
#define PRINT_VALUE(v){cout<<#v<<" :"<<(v)<<endl;}
PRINT_VALUE(argv[0])
string fileName="perfect";
assert(argc==2);
string num(argv[1]);
string inputFileName = fileName+num+".in";
string ansFileName = fileName+num+".ans";
auto ansFile = ifstream(ansFileName);
auto inputFile =ifstream(inputFileName);
int correctAns;
ansFile>>correctAns;
#define cin inputFile
#endif
cin.sync_with_stdio(false);
cin.tie(0);
l[1]=0;
l2[0]=0;
l2[1]=0;
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>sMin[i][0];
sMax[i][0]=sMin[i][0];
if(i!=1)l[i]=l[(i>>1)]+1;
}
int k=l[n]+1;
for(int i=2;i<=n;i++){
l2[i]=l2[i/2]+1;
}
int k=l2[n]+1;
for(int j=1;j<=k;j++){
for(int i=1;i+(1<<j)-1<=n;i++){
sMax[i][j]=max(sMax[i][j-1],sMax[i+(1<<(j-1))][j-1]);
sMin[i][j]=min(sMin[i][j-1],sMin[i+(1<<(j-1))][j-1]);
}
}
int ans=INT_MIN;
for(int l=1;l<=n;l++){
for(int r=l;r<=n;r++){
int j=l2[r-l+1];
PRINT_VALUE(l)
PRINT_VALUE(r)
PRINT_VALUE(r-(1<<j)+1)
PRINT_VALUE(j);
int maxlr=max(sMax[l][j],sMax[r-(1<<j)+1][j]);
int minlr=min(sMin[l][j],sMin[r-(1<<j)+1][j]);
ans=max(ans,maxlr^minlr);
}
}
cout<<ans<<endl;
#ifdef OITEST
PRINT_VALUE(ans);
PRINT_VALUE(correctAns);
assert(ans==correctAns);
#endif
}

View File

@ -28,7 +28,11 @@ target("binExp")
target("fperfect")
set_kind("binary")
add_files("./day5/perfect/fix.cpp")
add_tests("fperfect",{files="././day5/perfect/fix.cpp",defines="OITEST"})
set_rundir("./day5/perfect/")
for val=1,4 do
local strval = tostring(val)
add_tests(strval,{files="./day5/perfect/fix.cpp",defines="OITEST",runargs=strval,run_timeout=1000})
end
target("pre88")
set_kind("binary")