HDU1754线段树
来源:互联网 发布:雅思7分有多难 知乎 编辑:程序博客网 时间:2024/06/02 04:26
#include<iostream>#include<cstdio>using namespace std;struct node{ int s; int l,r; }; struct node tree[2000100]; int a[200010]; int create_tree(int h,int x,int y){//建树 int mid=(x+y)/2;//中间 tree[h].l=x;tree[h].r=y; if(x==y){//如果左右范围相等 tree[h].s=a[x]; return tree[h].s;}int a=create_tree(2*h,x,mid);//向两边分开递归 int b=create_tree(2*h+1,mid+1,y);tree[h].s=a>b?a:b; return tree[h].s;}int Q(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 a=Q(2*h,x,y);//向两侧分别递归 int b=Q(2*h+1,x,y); return a>b?a:b;;}int U(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 a=U(2*h,x); int b=U(2*h+1,x); tree[h].s=a>b?a:b; return tree[h].s; }int main(){int i,j,k,m,n,x,y;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++){ char c; getchar(); scanf("%c%d%d",&c,&x,&y); if(c=='Q'){ cout<<Q(1,x,y)<<endl; }else{ a[x]=y; U(1,x); } } }return 0;}
1 0
- HDU1754 线段树入门
- hdu1754 线段树
- hdu1754线段树入门
- hdu1754之线段树
- 线段树-HDU1754
- hdu1754(线段树)
- hdu1754 线段树
- hdu1754线段树
- hdu1754(线段树)
- hdu1754(线段树)
- HDU1754(线段树)
- Hdu1754【线段树】
- HDU1754 线段树
- HDU1754线段树
- hdu1754(线段树)
- HDU1754 线段树
- hdu1754线段树入门
- HDU1754 - 线段树 Water~
- 9. Swift 中的函数
- 【校内互测】陈老师搬书
- Python注释
- Java读取properties文件中文乱码问题解决
- hdu1213 How Many Tables
- HDU1754线段树
- 排版题 3
- mysql根据select查询结果 循环更改
- ionic 开发小问题集锦
- android-Building a Notification,Preserving Navigation when Starting an Activity
- AlertDialog编辑框无法调出输入法、锁定Activity方向、自定义进度条的WebView基础使用
- 一个对象怎么调用另一个对象, 打jar包,到底调用哪一个方法, 匿名对象, 空对象
- POJ2503字典树
- 使用Excel画甘特图