HDU 1754 I Hate It
来源:互联网 发布:阿里云学生没有库存 编辑:程序博客网 时间:2024/06/06 21:04
Simple segment tree;
The portal:http://acm.hdu.edu.cn/showproblem.php?pid=1754
#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <iostream>#include <algorithm>using namespace std;const int MAXN = 200005;struct Node {int value;int Left;int Right;}Segment_Tree[MAXN<<2];int a[MAXN];int cnt ;void Build_Tree(int Left,int Right,int Now) {Segment_Tree[Now].Left = Left;Segment_Tree[Now].Right = Right;if(Left == Right) {Segment_Tree[Now].value = a[cnt++];return ;}int Mid = (Left + Right) >> 1;Build_Tree(Left,Mid,Now<<1);Build_Tree(Mid+1,Right,Now<<1|1);Segment_Tree[Now].value = max(Segment_Tree[Now<<1].value,Segment_Tree[Now<<1|1].value);}void Update_Tree(int Left,int Right,int Now,int position,int change_value) {if(Left == Right) {Segment_Tree[Now].value = change_value;return;}int Mid = (Left + Right) >> 1;if(position > Mid) {Update_Tree(Mid+1,Right,Now<<1|1,position,change_value);}else {Update_Tree(Left,Mid,Now<<1,position,change_value);}Segment_Tree[Now].value = max(Segment_Tree[Now<<1].value,Segment_Tree[Now<<1|1].value);}int Query_Tree(int Left,int Right,int Now,int Left_Edge,int Right_Edge) {int Query_Ans = 0;if(Left >= Left_Edge && Right <= Right_Edge) {return Segment_Tree[Now].value;}int Mid = (Left + Right) >> 1;if(Mid >= Left_Edge) {Query_Ans = max(Query_Ans,Query_Tree(Left,Mid,Now<<1,Left_Edge,Right_Edge));}if(Mid < Right_Edge) {Query_Ans = max(Query_Ans,Query_Tree(Mid+1,Right,Now<<1|1,Left_Edge,Right_Edge));}return Query_Ans;}void Deal_with() {int n,m;while(~scanf("%d %d",&n,&m)) {for(int i = 1 ; i <= n ; i++) {scanf("%d",a+i);}cnt = 1;Build_Tree(1,n,1);char tempc;int position,value;for(int i = 1 ; i <= m ; i++) {getchar();scanf("%c %d %d",&tempc,&position,&value);if(tempc == 'U') {Update_Tree(1,n,1,position,value);}else {printf("%d\n",Query_Tree(1,n,1,position,value));}}}}int main(void) {//freopen("a.in","r",stdin);Deal_with();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
- hdu 2539 点球大战
- QLineEdit 输入验证(相关的设置)
- POJ 1056 IMMEDIATE DECODABILITY
- 关于rman duplicate 一些比较重要的知识点--系列三
- swift 可选类型,强制拆包,隐性拆包
- HDU 1754 I Hate It
- 稀疏表示综述:A Survey of Sparse Representation: Algorithms and Applications_2015(2)
- 海洋时代(葡萄牙)
- Linux 技巧:让进程在后台可靠运行的几种方法
- poj2559 Largest Rectangle in a Histogram
- 单源最短路径(Dijkstra)
- 通过配置worker_cpu_affinity参数提升nginx性能
- amaze ui 的使用
- 程序员必知的8大排序(四)-------归并排序,基数排序(java实现)