hdu1754I Hate It(线段树---单点更新,区间求值)
2013-08-06 20:29
357 查看
1.题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1754
2.参考代码:
http://acm.hdu.edu.cn/showproblem.php?pid=1754
2.参考代码:
#include <cstdio> #include <algorithm> using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 const int maxn=200000; int MAX[maxn<<2]; void PushUP(int rt){ MAX[rt]=max(MAX[rt<<1],MAX[rt<<1|1]); } void build(int l,int r,int rt){ if(l==r) { scanf("%d",&MAX[rt]); return ; } int m=(l+r)>>1; build(lson); build(rson); PushUP(rt); } void update(int p,int add,int l,int r,int rt){ ///单点替换 if(l==r) { MAX[rt]=add; return ; } int m=(l+r)>>1; if(p<=m) update(p,add,lson); else update(p,add,rson); PushUP(rt); } int query(int L,int R,int l,int r,int rt){ ///区间最值 if(L<=l &&r<=R) return MAX[rt]; int ret=0; int m=(l+r)>>1; if(L<=m) ret=max(ret,query(L,R,lson)); if(R>m) ret=max(ret,query(L,R,rson)); return ret; } int main() { int n,m,a,b; char s[2]; while(~scanf("%d %d",&n,&m)) { build(1,n,1); while(m--) { scanf("%s %d %d",s,&a,&b); if(s[0]=='Q') printf("%d\n",query(a,b,1,n,1)); else if(s[0]=='U') update(a,b,1,n,1); } } return 0; }
相关文章推荐
- HDU 1754 B I Hate It 线段树 单点更新 区间最大值 模板
- HDUOJ---1754 I Hate It (线段树之单点更新查区间最大值)
- hdu 1754 I Hate It(线段树之 单点更新+区间最值)
- hdu 1754 I Hate It 线段树单点更新区间查询
- HDU 1754 B I Hate It 线段树 单点更新 区间最大值 模板
- HDU 1754 I Hate It(线段树 单点更新 区间最大值)
- Hdu1754 I Hate It 线段树、单点更新+区间最值
- hdu 1754 I Hate It(线段树单点更新(a位置的值变成b)+区间求最值)
- HDU 1754 B I Hate It 线段树 单点更新 区间最大值 模板
- hdu3074Multiply game(线段树---单点更新,区间求值)
- HDU 1754 B I Hate It 线段树 单点更新 区间最大值 模板
- hdu 1754:I Hate It(线段树 单点更新+区间最值)
- HDU1754 I Hate It 线段树(单点更新,区间最值)
- HDU 1754 B I Hate It 线段树 单点更新 区间最大值 模板
- HDU 1754 B I Hate It 线段树 单点更新 区间最大值 模板
- hdu 1754 I Hate It 线段树 单点更新 区间最值
- HDU 1754 I hate it 【线段树--单点更新,区间最值】
- hdu 1754 I Hate It(线段树单点更新及区间最值)
- HDU 1754-I Hate It(线段树:单点更新,区间最值)
- hdu 1754 I Hate It(线段树,单点更新,区间最值)