hdu 1754
2013-03-31 22:16
183 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754
刚学的线段树,只能是现学现卖了,orz...
View Code
刚学的线段树,只能是现学现卖了,orz...
View Code
#include<iostream> #include<algorithm> const int MAXN=200004; using namespace std; int MAX[MAXN<<2]; void Push_Up(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(l,m,rt<<1); Build(m+1,r,rt<<1|1); Push_Up(rt); } void Updata(int p,int sc,int l,int r,int rt){ if(l==r){ MAX[rt]=sc; return ; } int m=(l+r)>>1; if(p<=m)Updata(p,sc,l,m,rt<<1); else Updata(p,sc,m+1,r,rt<<1|1); Push_Up(rt); } int Query(int L,int R,int l,int r,int rt){ if(L<=l&&r<=R){ return MAX[rt]; } int m=(l+r)>>1; int ret=0; if(L<=m)ret=max(ret,Query(L,R,l,m,rt<<1)); if(R>m)ret=max(ret,Query(L,R,m+1,r,rt<<1|1)); return ret; } int main(){ int n,m; while(~scanf("%d%d",&n,&m)){ Build(1,n,1); char str[4]; int a,b; for(int i=1;i<=m;i++){ scanf("%s%d%d",str,&a,&b); if(str[0]=='Q'){ printf("%d\n",Query(a,b,1,n,1)); }else Updata(a,b,1,n,1); } } return 0; }
相关文章推荐
- 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
- Hdu1754
- hdu1754 I Hate It
- hdu 1754 I Hate It
- HDU1754 I Hate It(线段树单点更新)
- hdu 1754 I Hate It 线段树
- 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(线段树求max)
- hdu 1754
- 数据结构_线段树_例题_ I Hate It(HDU 1754)
- [线段树]HDU 1754 I hate it