码迷,mamicode.com
首页 > 其他好文 > 详细

关于st表

时间:2019-09-19 21:25:34      阅读:89      评论:0      收藏:0      [点我收藏+]

标签:event   play   type   style   bdc   max   inline   getch   names   

技术图片
 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 }
代码

 

关于st表

标签:event   play   type   style   bdc   max   inline   getch   names   

原文地址:https://www.cnblogs.com/ljxfrbhhs/p/11552344.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!