poj-3264-Balanced Lineup-线段树-区域查询
来源:互联网 发布:路由器对网络稳定性 编辑:程序博客网 时间:2024/06/06 00:55
区域查询操作。
ma[i]:i区间内的最大值
mi[i]:i区间内的最小值
#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>#include<math.h>using namespace std;#define INF 99999999#define lmin 1#define rmax n#define lson l,(l+r)/2,rt<<1#define rson (l+r)/2+1,r,rt<<1|1#define root lmin,rmax,1#define maxn 55000int cl[maxn*4];int ma[maxn*4];int mi[maxn*4];int num[maxn];void push_up(int rt){ ma[rt]=max(ma[rt<<1],ma[rt<<1|1]); mi[rt]=min(mi[rt<<1],mi[rt<<1|1]);}void push_down(int rt){ if(cl[rt]!=-1) { cl[rt<<1]=cl[rt]; cl[rt<<1|1]=cl[rt]; cl[rt]=-1; }}void creat(int l,int r,int rt){ if(l==r) { scanf("%d",&cl[rt]); ma[rt]=mi[rt]=cl[rt]; return; } creat(lson); creat(rson); push_up(rt);}void update(int ll,int rr,int x,int l,int r,int rt){ if(l>rr||r<ll)return; if(ll<=l&&rr>=r) { cl[rt]+=x; return; } // push_down(rt); update(ll,rr,x,lson); update(ll,rr,x,rson); push_up(rt);}int query(int ll,int rr,int l,int r,int rt){ if(r<ll)return 0; if(l>rr)return 0; if(ll<=l&&rr>=r)return ma[rt]; return max(query(ll,rr,lson),query(ll,rr,rson));}int query1(int ll,int rr,int l,int r,int rt){ if(r<ll)return INF; if(l>rr)return INF; if(ll<=l&&rr>=r)return mi[rt]; return min(query1(ll,rr,lson),query1(ll,rr,rson));}int main(){ int T,_,n,l,r,st,x,m; char str[110]; while(~scanf("%d%d",&n,&m)) { creat(root); while(m--) { scanf("%d%d",&l,&r); printf("%d\n",query(l,r,root)-query1(l,r,root)); } } return 0;}
0 0
- poj-3264-Balanced Lineup-线段树-区域查询
- 查询线段树 Balanced Lineup POJ
- POJ 3264 Balanced Lineup 线段树的构建+区间查询
- POJ 3264 Balanced Lineup (线段树单点更新 区间查询)
- POJ 3264 Balanced Lineup(线段树区间查询)
- poj 3264 Balanced Lineup rmq/线段树
- POJ 3264 Balanced Lineup RMQ / 线段树
- POJ 3264 Balanced Lineup 线段树基础
- poj 3264 Balanced Lineup[线段树,,水]
- 【线段树】 POJ 3264 Balanced Lineup
- poj 3264 Balanced Lineup 基础线段树
- poj 3264 Balanced Lineup(线段树)
- POJ 3264 Balanced Lineup 线段树
- Poj 3264 Balanced Lineup - 线段树
- POJ 3264 - Balanced Lineup(线段树)
- POJ 3264 Balanced Lineup (RMQ线段树)
- POJ 3264 Balanced Lineup 线段树RMQ
- [线段树] POJ 3264 balanced lineup
- 黑马程序员_IO流(一)
- C/C++: C++ 中 const_cast 的含义
- 使用LaTeX书写数学公式简要入门
- 黑马程序员_IO流(二)_File类、其他流
- 网络121第3周实验
- poj-3264-Balanced Lineup-线段树-区域查询
- 数字图像处理的就业前景
- JAVA的基本数据类型和引用数据类型的区别
- Linux下的mysql命令
- oracle安装
- 黑马程序员_多线程及单例模式
- 日本人的选择
- 变量类型
- hdu-1698-Just a Hook-线段树-区域更新,区域查询