HDU1754-I Hate It
来源:互联网 发布:淘宝网折叠沙发床单人 编辑:程序博客网 时间:2024/05/22 15:10
【题目】:HDU1754
【题意】:给出初始学生的成绩,然后有2个操作,一个操作是修改成绩, 一个操作是查询区间最大值。
【题解】:用维护区间最大值的方法进行更新。max【rt】=max(max【rt<<1】,max【rt<<1|1】);
【代码】:
#include<stdio.h>#include<iostream>#include<algorithm>using namespace std;#define lson l,mid,rt<<1#define rson mid+1,r,rt<<1|1const int maxn=222222;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 mid=(l+r)>>1; Build(lson); Build(rson); pushup(rt);}void update(int p,int q,int l,int r,int rt){ if(l==r){ MAX[rt]=q; return ; } int mid=(l+r)>>1; if(p<=mid)update(p,q,lson); else update(p,q,rson); pushup(rt);}int query(int L,int R,int l,int r,int rt){ if(L<=l&&r<=R){ return MAX[rt]; } int mid=(l+r)/2; int ret=0; if(L<=mid)ret=max(ret,query(L,R,lson)); if(R>mid)ret=max(ret,query(L,R,rson)); return ret;}int main(){ int n,m; while(scanf("%d %d",&n,&m)!=EOF){ Build(1,n,1); for(int i=0;i<m;i++){ char op[2]; cin>>op; if(op[0]=='Q'){ int a,b; cin>>a>>b; cout<<query(a,b,1,n,1)<<endl; } else{ int a,b; cin>>a>>b; update(a,b,1,n,1); } } } return 0;}
0 0
- hdu1754 I Hate It
- HDU1754 I Hate It
- HDU1754:I Hate It
- HDU1754--I Hate It
- HDU1754 I hate it
- hdu1754 I Hate It
- HDU1754:I Hate It
- hdu1754 I Hate It
- hdu1754 I Hate It
- hdu1754 I Hate It
- hdu1754 I Hate It
- hdu1754 I Hate It
- hdu1754 I Hate it
- HDU1754 I Hate It
- hdu1754 I Hate It
- hdu1754 I Hate It
- HDU1754 I Hate It
- HDU1754 I Hate It
- TF-IDF
- 雾山的Java学习笔记---I/O(三)(处理流)
- Ubuntu 下字体问题链接搜集
- Visual C++ 2012入门经典(第6版) 课后练习(第06章)
- static的含义以及其在C/C++中的区别
- HDU1754-I Hate It
- 【Leetcode长征系列】Valid Sudoku
- APC Silcon 60kv - What do all the abbreviations mean
- [Phonegap+Sencha Touch] 移动开发7、Sencha Touch图标的使用与自定义
- 颜色特征描述子的SIFT/SURF
- ZOJ Monthly, June 2014 F - First Digit
- ASP.NET MVC学习---(六)CRUD例子补充
- HDU 1695 GCD (数论-整数和素数,欧拉函数,组合数学-容斥原理)
- AUX/奥克斯 T8300 root教程_方法