hdu1754I Hate It(线段树)
来源:互联网 发布:mmd h 动作数据 编辑:程序博客网 时间:2024/06/14 08:59
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1754
好久没做线段树的题了,先来一道简单的练手,就是端点更新,区间最大值。。看了大神的代码,风格法很飘逸~
#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>#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);}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,lson); else updata(p,sc,rson); pushup(rt);}int query(int L,int R,int l,int r,int rt){ int ret=0; if(L<=l && r<=R) return MAX[rt]; 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; while (~scanf("%d%d",&n,&m)) { build(1 , n , 1); while (m --) { char op[2]; int a , b; scanf("%s%d%d",op,&a,&b); if (op[0] == 'Q') printf("%d\n",query(a , b , 1 , n , 1)); else updata(a , b , 1 , n , 1); } } return 0;}
0 0
- 线段树-HDU1754I Hate It
- hdu1754I Hate It(线段树)
- 线段树之HDU1754I Hate It
- hdu1754I Hate It(线段树---单点更新,区间求值)
- hdu1754I Hate It
- hdu1754I Hate It
- hdu1754I Hate It
- hdu1754_I Hate It(线段树)
- I Hate It (线段树)
- 线段树:I Hate It
- i hate it 线段树
- I Hate It 【线段树】
- I Hate It---线段树
- I hate it --线段树
- I Hate It (线段树)
- 线段树i hate it
- I Hate It(线段树)
- I hate it HDU【线段树】
- SimpleDateFormat用法大全及易错分析
- JavaScipr Attr 对checkbox失效问题
- POI导出EXCEL经典实现
- 严重: Exception starting filter struts2 java.lang.NullPointerException
- 解决 百度地图+slidingmenu 切换Fragment闪黑屏问题
- hdu1754I Hate It(线段树)
- java 嵌入式的Web服务器jetty使用例子
- 缓冲区溢出分析第07课:MS06-040漏洞研究——静态分析
- POJ-3468-线段树-A Simple Problem with Integers
- 文本二叉树
- 挂载和卸载u盘(centos)
- 关于女人强势表现和强势心理
- Spring注解详解
- 缓冲区溢出分析第08课:MS06-040漏洞研究——动态调试