关于st表
程序员文章站
2022-05-18 21:06:45
1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 int n,m; 8 int logg[100005 ......
1 #include<cstdio> 2 #include<iostream> 3 #include<cmath> 4 #include<cctype> 5 #include<algorithm> 6 using namespace std; 7 int n,m; 8 int logg[100005]; 9 int maxx[100005][18]; 10 inline int read(){ 11 int ret=0; 12 char ch=getchar(); 13 while(ch<'0'||ch>'9')ch=getchar(); 14 while(ch>='0'&&ch<='9')ret=ret*10+ch-'0',ch=getchar(); 15 return ret; 16 } 17 int main(){ 18 n=read(),m=read(); 19 logg[0]=-1; 20 for(int i=1;i<=n;++i)maxx[i][0]=read(),logg[i]=logg[i>>1]+1; 21 for(int i=1;i<=18;++i){ 22 for(int j=1;j+(1<<i)-1<=n;++j){ 23 maxx[j][i]=max(maxx[j][i-1],maxx[j+(1<<i-1)][i-1]); 24 } 25 } 26 for(int i=1;i<=m;++i){ 27 int l,r; 28 l=read();r=read();int len=logg[r-l+1]; 29 cout<<max(maxx[l][len],maxx[r-(1<<len)+1][len]);putchar('\n'); 30 } 31 return 0; 32 }
上一篇: 使用PHP开发HR系统(5)