hdu 1754 I Hate It
来源:互联网 发布:淘宝客佣金 编辑:程序博客网 时间:2024/06/05 07:14
题目链接 hdu 1754 I Hate It
线段树单点更新 求区间最大值
//线段树单点更新#include<iostream>#include<cstdio>#include<cstdlib>#define maxn 222222#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1using namespace std;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);}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 MAX=-1; if(L<=m) MAX=max(MAX,query(L,R,lson)); if(R>m) MAX=max(MAX,query(L,R,rson)); return MAX;}void update(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) update(p,sc,lson); else update(p,sc,rson); pushup(rt);}int main(){ int n,m; while(~scanf("%d%d",&n,&m)) { build(1,n,1); while(m--) { char op; int a,b; scanf(" %c%d%d",&op,&a,&b); if(op=='Q') printf("%d\n",query(a,b,1,n,1)); else update(a,b,1,n,1); } }}
0 0
- 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 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 I Hate It
- hdu 1754 I Hate It
- hdu 1754 I hate it
- HDU 1754 I Hate It
- iOS程序崩溃,提示[__NSCFArray removeObjectAtIndex:]: mutating method sent to immutable object’的解决办法
- GCD 同步异步的串行和并发问题
- 注释规范判断
- 面试技巧
- 文件/目录操作(5)——cp、scp、mv、ln命令
- hdu 1754 I Hate It
- linux su命令参数及用法详解(linux切换用户命令)
- HDOJ-5500Reorder the Books(规律)
- viewgroup自定义组件 --- 侧滑组件
- 单元测试的主要内容
- 小脚本清理垃圾文件使电脑变快
- SecurityContextHolder, SecurityContext and Authentication Objects
- 软件系统中用户文档的测试要点
- C#将遨游收藏夹中的网页自动保存到本地