hdu 1754 也是裸的线段树
2013-01-09 15:05
218 查看
我知道了 while(~scanf("%d%d",&n,&m)) 等价于 while(scanf("%d%d",&n,&m)!=EOF)
是等价的。
而且以后用c语言输入时候的scanf("%c“,&c),这种要注意到回车空格神马的。
是等价的。
而且以后用c语言输入时候的scanf("%c“,&c),这种要注意到回车空格神马的。
#include <stdio.h> #include <algorithm> #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define maxn 880000 using namespace std; int sum[maxn]; void PushUp(int rt) { sum[rt]=max(sum[rt<<1],sum[rt<<1|1]); } void build(int l,int r,int rt) { if(l==r) { scanf("%d",&sum[rt]); return; } int m=(l+r)>>1; build(lson); build(rson); PushUp(rt); } void update(int p,int c,int l,int r,int rt) { if(l==r) { sum[rt]=c; return; } int m=(l+r)>>1; if(p<=m) update(p,c,lson); else update(p,c,rson); PushUp(rt); } int query(int L,int R,int l,int r,int rt) { if(L<=l&&r<=R) { return sum[rt]; } int m=(l+r)>>1; int res=0; if(L<=m) res=max(res,query(L,R,lson)); if(R>m) res=max(res,query(L,R,rson)); return res; } int main() { int m,n,i,j; char c[10]; int a,b; while(~scanf("%d%d",&n,&m)) { build(1,n,1); while(m--) { scanf("%s%d%d",c,&a,&b); if(c[0]=='Q') printf("%d\n",query(a,b,1,n,1)); else update(a,b,1,n,1); } } return 0; }
相关文章推荐
- HDU 1754 I Hate It (线段树)
- HDU1754(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【线段树】
- hdu——1754(线段树求最值)
- hdu 1754 I Hate It【线段树,单点替换,区间最值】
- HDU 1754 线段树
- 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_线段树
- HDU 1754 I Hate It (线段树)
- hdu 1754 I Hate It 线段树单点更新区间查询
- 线段树学习小记 Hdu 1754+Poj 3264 (区间最值)
- hdu 1754 I hate it(线段树)
- [置顶] HDU 1754 线段树