update st

This commit is contained in:
Zengtudor 2024-08-08 00:14:36 +08:00
parent cd16421688
commit 002d394e54
5 changed files with 49 additions and 2 deletions

View File

@ -1,5 +1,6 @@
5 5
5
1 2 3 4 5
5
1 2
2 3
3 4

30
day5/RMQ/st_done.cpp Normal file
View File

@ -0,0 +1,30 @@
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int l2[n+1];
l2[1]=0;
for(int i=2;i<=n;i++){
l2[i]=l2[i>>1]+1;
}
int k=l2[n]+1;
int s[n+1][k+1];
for(int i=1;i<=n;i++){
cin>>s[i][0];
}
for(int j=1;j<=k;j++){
for(int i=1;i+(1<<j)-1<=n;i++){
s[i][j]=min(s[i][j-1],s[i+(1<<(j-1))][j-1]);
}
}
int m;
cin>>m;
for(int i=1;i<=m;i++){
int l,r;
cin>>l>>r;
int j=l2[r-l+1];
cout<<min(s[l][j],s[r-(1<<j)+1][j])<<endl;
}
}

View File

@ -1,3 +1,5 @@
//NOT DONE
//TODO BUGFIX
#include<bits/stdc++.h>
using namespace std;

6
test.cpp Normal file
View File

@ -0,0 +1,6 @@
#include <bits/stdc++.h>
using namespace std;
int main(){
cout<<(8>>1)<<endl;
}

View File

@ -3,4 +3,12 @@ target("st_raw")
set_kind("binary")
add_files("day5/RMQ/st_raw.cpp")
-- add_cxxflags("-DOIDEBUG")
set_rundir("./day5/RMQ")
set_rundir("./day5/RMQ")
target("st_done")
set_kind("binary")
add_files("./day5/RMQ/st_done.cpp")
target("test")
set_kind("binary")
add_files("test.cpp")