RMQ模板题 POJ 3264
来源:互联网 发布:淘宝商品如何推广 编辑:程序博客网 时间:2024/06/08 19:41
#include<cstdio>#include<iostream>#include<cmath>using namespace std;int n,m,temp2,emax[50001][19],emin[50001][19],k,l,r,maxx,minn,res;double temp;int main(){ scanf("%d%d",&n,&m); for (int i=1;i<=n;i++) { scanf("%d",&temp2); emax[i][0]=emin[i][0]=temp2; } temp=log(n)/log(2.0); for (int j=1;j<=temp;j++) { for (int i=1;i<=n;i++) { if (i+(1<<j)-1<=n) { emax[i][j]=max(emax[i][j-1],emax[i+(1<<(j-1))][j-1]); emin[i][j]=min(emin[i][j-1],emin[i+(1<<(j-1))][j-1]); } } } for (int i=1;i<=m;i++) { scanf("%d%d",&l,&r); if (l>r) { swap(l,r); } k=log(r-l+1)/log(2); maxx=max(emax[l][k],emax[r-(1<<k)+1][k]); minn=min(emin[l][k],emin[r-(1<<k)+1][k]); res=maxx-minn; printf("%d\n",res); } return 0;}
0 0
- poj 3264 -- RMQ模板题
- RMQ模板题 POJ 3264
- poj 3264(模板RMQ)
- POJ 3264 RMQ模板
- POJ 3264 【RMQ模板】
- POJ 3264 Balanced Lineup【RMQ模板题】
- 简单RMQ模板题 POJ 3264
- POJ-3264 Balanced Lineup(rmq模板题)
- poj 3624 RMQ模板题
- poj 3264 Balanced Lineup--RMQ问题模板题
- (模板题)poj 3264 Balanced Lineup(RMQ的ST算法)
- poj 3264 Balanced Lineup (RMQ算法 模板题)
- POJ 3264 Balanced Lineup【RMQ附模板】
- POJ 3264 Balanced Lineup(RMQ模板)
- POJ 1330 LCA转RMQ模板题
- poj 3246 RMQ模板
- LCA & RMQ 模板 POJ 1330
- POJ 3264 Balanced Lineup 【RMQ求区间最值模板题】
- 浅析互斥锁与条件变量的使用
- 打开转发IP功能(IP forwarding)
- java load property
- 传纸条 优化
- linux文件学习9
- RMQ模板题 POJ 3264
- Windows7/10 64Bit安装Theano并实现GPU加速
- 【Android 进阶:翻译】Get Started With Firebase for Android
- composer autoload原理浅析
- 基础知识
- java网络编程之TCP
- 高数常考考点总结
- Kaldi中的plda的训练以及computer-socre
- Android6.0读取通话记录