hdu5443 The Water Problem(线段树)
来源:互联网 发布:c语言long范围 编辑:程序博客网 时间:2024/05/20 05:58
求区间最大值 写了一颗线段树
比赛的时候第一眼就看见了这个 - -
但是手速太慢了还是写了8分多钟
#include <bits/stdc++.h>#define lson num<<1#define rson num<<1|1#define gl l,m,lson#define gr m+1,r,rson#define PARA int l=1,int r=n,int num=1using namespace std;const int MAXN = 1e6+10;int n;struct SegTree{ int st[MAXN<<2]; void init(PARA) { if(l==r) scanf("%d",&st[num]); else { int m=l+r>>1; init(gl); init(gr); st[num]=max(st[lson],st[rson]); } } int query(int a,int b,PARA) { if(a<=l&&r<=b) return st[num]; else { int m=l+r>>1; if(b<=m) return query(a,b,gl); else if(a>m) return query(a,b,gr); else return max(query(a,b,gl),query(a,b,gr)); } }}soul;int main(){ int T,m; scanf("%d",&T); while(T--) { scanf("%d",&n); soul.init(); int a,b; scanf("%d",&m); while(m--) { scanf("%d%d",&a,&b); printf("%d\n",soul.query(a,b)); } } return 0;}
0 0
- hdu5443 The Water Problem(线段树)
- HDU5443 - The Water Problem (线段树)
- hdu5443 The Water Problem
- hdu5443 The Water Problem(长春网络赛)
- HDOJ5443 The Water Problem(线段树)
- HDU 5443The Water Problem 线段树
- 【线段树】HDU 5443 The Water Problem
- hduoj 5443 The Water Problem【线段树】
- hdu5443 【线段树】
- HDU5443——The Water Problem(2015年长春区域赛)
- hdu-5443-The Water Problem -裸的RMQ线段树
- ACM the water problem详解[C语言][线段树]
- HDOJ 5443 The Water Problem(线段树区间最值)(长春网络赛)
- hdoj The Water Problem 5443 (线段树区间最值问题)
- HDU 5443 The Water Problem(线段树水题)
- water problem(线段树 容易)
- qduoj water problem(线段树)
- The Water Problem(RMQ)
- 第2周SHH数据结构—【项目3-体验复杂度(1)】
- 我学shell编程2
- 9月JAVA WEB开发杂烩
- P2P、P2C 、O2O 、B2C、b2b、C2C、I2CF...各种互联网名词详解
- 前端自动化测试探索
- hdu5443 The Water Problem(线段树)
- 第三周项目1-顺序表的基本运算(1)CreateList
- IOS基础学习之--@dynamic和@synthsize
- Java集合面试题小结
- assoc.c
- 第2周项目三 体验复杂度
- HDU 5446 Unknown Treasure(CRT+lucas定理)
- 第二周
- linux下网卡配vlan