st表
来源:互联网 发布:长远汽配软件视频教程 编辑:程序博客网 时间:2024/04/28 07:09
#include<cstdio>#include<algorithm>#include<cstring>#define maxn 100005#define dep 17using namespace std;int n,m,lg[maxn],st[dep][maxn];int main(){scanf("%d%d",&n,&m);for(int i=1;i<=n;i++)scanf("%d",&st[0][i]);for(int j=1;j<dep;j++)for(int i=1;i<=n;i++){st[j][i]=st[j-1][i];if(i+(1<<j-1)<=n && st[j-1][i+(1<<j-1)]>st[j][i])st[j][i]=st[j-1][i+(1<<j-1)];}int tmp=1;for(int i=0;i<dep;i++,tmp<<=1)lg[tmp]=i;tmp=0;for(int i=1;i<=n;i++){tmp=max(lg[i],tmp);lg[i]=tmp;}int l,r;for(int i=1;i<=m;i++){scanf("%d%d",&l,&r);tmp=lg[r-l+1];printf("%d\n",max(st[tmp][l],st[tmp][r-(1<<tmp)+1]));}}
阅读全文
0 0
- ST表
- st表
- st表
- st表
- ST表
- st表
- ST表
- ST表
- st表
- ST表
- ST表
- ST 稀疏表
- ST(稀疏表)算法
- ST表学习笔记
- HDU5443->ST表
- 【RMQ算法】ST表
- Sparse Table ST表
- ST表LCA模板
- greenDao数据库升级
- 【bzoj1783】[Usaco2010 Jan]Taking Turns
- 2017.11.3笔记
- Vuex核心概览
- 十一月三日课堂笔记
- st表
- 封装日期时间自定义格式方法
- Error:Unsupported method: BaseConfig.getApplicationIdSuffix().
- 概率图模型
- 【Redis笔记-10】Redis的设置数据库密码
- C#学习笔记:栈溢出异常(StackOverflowException)
- Win7上使用VM安装Max系统后如何使用网络
- LeetCode--Merge Two Sorted Lists(合并两个有序链表)Python
- java传引用还是传值的问题