Hdu 1754 I Hate It
来源:互联网 发布:许晴航母 知乎 编辑:程序博客网 时间:2024/05/16 06:36
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754
线段树处理单点更新,区间最值问题模型。。
#include <iostream>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#include <map>#include <queue>#include <algorithm>using namespace std;#define Maxn 200005#define lx (x<<1)#define rx (x<<1 | 1)#define MID ((l + r)>>1)int A[Maxn];int S[Maxn<<2];void pushUp(int x){ S[x] = max(S[lx],S[rx]);}void build(int l,int r,int x){ if(l == r) { S[x] = A[l]; return; } build(l,MID,lx); build(MID+1,r,rx); pushUp(x);}int query(int L,int R,int l,int r,int x){ if(L<=l && r<=R) return S[x]; int ans = 0; if(L<=MID) ans = max(ans,query(L,R,l,MID,lx)); if(MID<R) ans = max(ans,query(L,R,MID+1,r,rx)); return ans;}void update(int p,int d,int l,int r,int x){ if(l == r) { S[x] = d; return; } if(p <= MID) update(p,d,l,MID,lx); else update(p,d,MID+1,r,rx); pushUp(x);}int main(){#ifndef ONLINE_JUDGE freopen("in.txt","r",stdin);#endif int m,n; char cmd[10]; int a,b; while(scanf(" %d %d",&n,&m)!=EOF) { for(int i=1;i<=n;i++) scanf(" %d",&A[i]); build(1,n,1); while(m--) { scanf(" %s",cmd); scanf(" %d %d",&a,&b); if(cmd[0] == 'Q') printf("%d\n",query(a,b,1,n,1)); else if(cmd[0] == 'U') update(a,b,1,n,1); } } return 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
- cocos2d-x 输入框CCEditBox的使用
- org.hibernate.MappingException: Unknown entity:
- eclipse Rcp 打开word,并能编辑
- 关于递归的小探索
- PHP-CGI 进程 CPU 100% 与 file_get_contents 函数的关系
- Hdu 1754 I Hate It
- Changing the contrast and brightness of an image!
- 网站的分布式架构
- Linux下软件的安装与卸载方法
- 超简单的javabean应用
- Java程序优化的一些最佳实践
- mysql中int、bigint、smallint 和 tinyint的区别与长度
- 【转】对setTimeout的误差堆积测试和简单分析
- 怎么对包含自定义对象的NSMutableArray排序