ST表
来源:互联网 发布:为什么淘宝没有卖巴豆 编辑:程序博客网 时间:2024/04/28 07:51
求最大值
#include<iostream>#include<stdio.h>#include<algorithm>#include<cmath>#define II int#define R register#define I 123456using namespace std;II f[I][30];II n,q;int main(){ scanf("%d%d",&n,&q); for(R II i=1;i<=n;i++) scanf("%d",&f[i][0]); for(R II i=1;(1<<i)<=n;i++) // 这里(1<<j)<=n; { R II o=1<<i; for(R II j=1;j<=n-o+1;j++) // 这里要j<=n-o+1; { f[j][i]=max(f[j][i-1],f[j+(o>>1)][i-1]); } } while (q--) { R II l,r,ans=-1e9; scanf("%d%d",&l,&r); R II o=log(r-l+1)/log(2); ans=max(f[l][o],f[r-(1<<o)+1][o]); printf("%d\n",ans); } exit(0);}
阅读全文
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模板
- 工作所遇到的不清楚的名词集合
- html之自定义插件初级版
- yii2 事务处理
- 通达oa破解版/通达oa破解补丁/通达oa破解版下载/2017
- 【接口测试】-总结-关于spring框架的数据库连接配置
- ST表
- Python图像处理库PIL-convert()函数
- Jmeter性能测试(HTTP协议)
- java基础----集合hashMap
- ORA-00704和ORA-39700错误
- Activity的四种启动模式
- 洛谷 1032 [NOIP2002] 字串变换 双向bfs
- kafka学习之路(一)——入门
- 深度学习在目标跟踪中的应用