HDU1754 线段树 (完全二叉树)
来源:互联网 发布:a2淘宝旗舰店是真的吗 编辑:程序博客网 时间:2024/05/20 18:53
#include<stdio.h>#include<string.h>#include<stdlib.h>const int maxn=200000+10;struct node{int s;int l,r;};struct node tree[maxn*10];int a[maxn];int max(int x,int y){return x>y?x:y;}int create_tree(int h,int x,int y){tree[h].l=x;tree[h].r=y;int mid=(x+y)/2;if(x==y){tree[h].s=a[x];return tree[h].s;}int x1=create_tree(h*2,x,mid);int x2=create_tree(h*2+1,mid+1,y);tree[h].s=max(x1,x2);return tree[h].s;}int dfs(int h,int x,int y){if(y<tree[h].l || x>tree[h].r)return 0;if(x<=tree[h].l && y>=tree[h].r)return tree[h].s;int x1=dfs(2*h,x,y);int x2=dfs(2*h+1,x,y);return max(x1,x2);}int update(int h,int x){if(x<tree[h].l || x>tree[h].r)return tree[h].s;if(tree[h].l==tree[h].r){tree[h].s=a[tree[h].l];return tree[h].s;}int x1=update(2*h,x);int x2=update(2*h+1,x);tree[h].s=max(x1,x2);return tree[h].s;}int main(){int i,j,k,m,n;int x,y;char c;while(scanf("%d%d",&n,&m)!=EOF){for(i=1;i<=n;i++)scanf("%d",&a[i]);create_tree(1,1,n);for(i=1;i<=m;i++){getchar();scanf("%c %d %d",&c,&x,&y);if(c=='Q'){printf("%d\n",dfs(1,x,y));}else{ a[x]=y;update(1,x);}}}return 0;}
4 0
- HDU1754 线段树 (完全二叉树)
- hdu1754(线段树)
- hdu1754(线段树)
- hdu1754(线段树)
- hdu1754(线段树)(裸题)
- HDU1754 线段树入门
- hdu1754 线段树
- hdu1754线段树入门
- hdu1754之线段树
- 线段树-HDU1754
- hdu1754 线段树
- hdu1754线段树
- hdu1754(线段树)
- HDU1754(线段树)
- Hdu1754【线段树】
- HDU1754 线段树
- HDU1754线段树
- HDU1754 线段树
- Selenium的延迟等待
- activemq 控制面板说明
- android_空指针异常
- web-inf文件下的页面间的相互跳转
- 34. Element textContent 属性
- HDU1754 线段树 (完全二叉树)
- jquery表单ajax提交以及checkbox全选/全不选 .
- DDoS攻击原理及防护方法论
- tex中文论文
- 检测网络是否可用
- java反射的简单理解
- hive优化总结
- [IOS]今天开始学UI---UIPageControl
- 35. Element title 属性