hdu 1754 I Hate It
来源:互联网 发布:淘宝禁售商品纠纷 编辑:程序博客网 时间:2024/06/11 16:51
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1754
寻找区间最大值。
#include <iostream>#include <cstdio>#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1using namespace std;const int maxn = 200005;int tree[maxn<<2];char str[10];void PushUp(int rt){ tree[rt] = max(tree[rt<<1],tree[rt<<1|1]);}void build(int l, int r, int rt){ if (l == r){ scanf("%d",&tree[rt]); return; } int m = (l + r) >> 1; build (lson); build (rson); PushUp(rt);}void update(int id ,int p, int l, int r, int rt){ if (l == r){ tree[rt] = p; return ; } int m = (l + r) >> 1; if (id <= m) update(id,p,lson); else update(id,p,rson); PushUp(rt);}int query(int L,int R,int l,int r,int rt){ if(L <= l && r <= R){ return tree[rt]; } int m = (l + r)>>1; int ret = 0; 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); int a,b; while(m--){ scanf("%s",str); scanf("%d%d",&a,&b); if(str[0] == 'Q') printf("%d\n",query(a,b,1,n,1)); else if(str[0] == 'U') update(a,b,1,n,1);// for(int i = 1;i < n*4;i++)// printf("%d ",tree[i]);// printf("\n"); } } return 0;}
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
- POJ 1182
- spring的beanFactory和factoryBean
- Linux下常见命令
- Android如何绘制视图,解释了为何onMeasure有时要调用多次
- XStream在类与JSON对象之间转换
- hdu 1754 I Hate It
- C++ 虚拟继承
- AdvancedDataGrid高级数据网格加入自定义链接按钮LinkButton
- Ajax 小记with 用法
- UVA 11227 The silver bullet.(简单题:枚举经过最多的点的直线)
- 数据库函数依赖
- openstack ice自定义调度算法项目详解(horizon、novaclient、api、scheduler、db、自定义数据库)
- CoreText实现图文混排和点击事件
- Hibernate,一对多的关联关系