#include <iostream>
#include <cstdio>
using namespace std; #define MAXN 200005 int N,M; int grade[MAXN]; struct node
{
int left;
int right;
int max;
}Tree[MAXN*20]; int Build(int start,int end,int root)
{
Tree[root].left = start;
Tree[root].right = end; if(start == end)
{
Tree[root].max = grade[start];
return Tree[root].max;
} int mid = (start + end)/2; int a = Build(start,mid,root*2);
int b = Build(mid+1,end,(root*2)+1); return Tree[root].max = max(a,b);
} int find(int start,int end,int root)
{
if(start > Tree[root].right || end < Tree[root].left)
return 0; if(start <= Tree[root].left && Tree[root].right <= end)
return Tree[root].max; int a = find(start,end,root*2);
int b = find(start,end,(root*2)+1); return max(a,b);
} int update(int root,int pos,int value)
{
if(pos < Tree[root].left || pos > Tree[root].right)
return Tree[root].max; if(Tree[root].left == pos && Tree[root].right == pos)
return Tree[root].max = value; int a = update(root*2,pos,value);
int b = update((root*2)+1,pos,value); Tree[root].max = max(a,b);
return Tree[root].max;
} int main()
{
while(scanf("%d%d",&N,&M)!=EOF)
{
for(int i = 1; i <= N; i++)
{
scanf("%d",&grade[i]);
}
Build(1,N,1);
char ch;
int A,B;
while(M--)
{
getchar();
scanf("%c%d%d",&ch,&A,&B);
if(ch == 'Q')
cout<<find(A,B,1)<<endl;
else if(ch == 'U')
{
grade[A] = B;
update(1,A,B);
} }
}
return 0;
}

hdu1754线段树维护区间最大值的更多相关文章

  1. 51nod 1376【线段树维护区间最大值】

    引自:wonter巨巨的博客 定义 dp[i] := 以数字 i(不是下标 i)为结尾的最长上升长度 然后用线段树维护 dp[i]: 每个节点维护 2 个信息,一个是当前区间的最大上升长度,一个是最大 ...

  2. HDU 2795 Billboard 【线段树维护区间最大值&&查询变形】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=2795 Billboard Time Limit: 20000/8000 MS (Java/Others) ...

  3. 【HDOJ 1337】I Hate It(线段树维护区间最大值)

    Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少.这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写 ...

  4. 洛谷P3113 [USACO14DEC]马拉松赛跑Marathon_Gold 线段树维护区间最大值 模板

    如此之裸- Code: #include<cstdio> #include<cstring> #include<cmath> #include<algorit ...

  5. POJ.2763 Housewife Wind ( 边权树链剖分 线段树维护区间和 )

    POJ.2763 Housewife Wind ( 边权树链剖分 线段树维护区间和 ) 题意分析 给出n个点,m个询问,和当前位置pos. 先给出n-1条边,u->v以及边权w. 然后有m个询问 ...

  6. Can you answer these queries V SPOJ - GSS5 (分类讨论+线段树维护区间最大子段和)

    recursion有一个整数序列a[n].现在recursion有m次询问,每次她想知道Max { A[i]+A[i+1]+...+A[j] ; x1 <= i <= y1 , x2 &l ...

  7. 线段树维护区间前k小

    线段树维护区间前k小 $ solution: $ 觉得超级钢琴太麻烦?在这里线段树提供一条龙服务 . 咳咳,开始讲正题!这道题我们有一个和超级钢琴复杂度一样 $ ~O(~\sum x\times lo ...

  8. CodeForces - 587E[线段树+线性基+差分] ->(线段树维护区间合并线性基)

    题意:给你一个数组,有两种操作,一种区间xor一个值,一个是查询区间xor的结果的种类数 做法一:对于一个给定的区间,我们可以通过求解线性基的方式求出结果的种类数,而现在只不过将其放在线树上维护区间线 ...

  9. HDU-1754 I Hate It(线段树,区间最大值)

    很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少.  这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问.当然,老师 ...

随机推荐

  1. LINQ语句

    http://wenku.baidu.com/link?url=hPKqDWql7DNr6W2MsINakjRYYNXmXywB_U3h9FFMeFjcToYpusI2fYKgHjZSRq7r3ULG ...

  2. 【php】对PHPExcel一些简单的理解

    这里有关于excel文件的几个概念需要跟大家说明一下,这几个概念对于我们的后续编程是很有帮助的:1.工作簿:在excel环境中用来存储数据并处理数据的文件,又称为excel文件或excel文档,   ...

  3. 【POJ】3294 Life Forms

    后缀数组. /* 3294 */ #include <iostream> #include <sstream> #include <string> #include ...

  4. 1019.Line Painting(线段树 离散化)

    1019 离散化都忘记怎么写了 注意两个端点 离散化后用线段树更新区间 混色为-1  黑为2  白为1  因为N不大 最后直接循环标记这一段的颜色查找 #include <iostream> ...

  5. 基于邻接矩阵的广度优先搜索遍历(BFS)

    题目:http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2141&cid=1186 #include<stdio.h> #incl ...

  6. poj3225 线段树区间操作 (见鬼)

    细节处理实在太重要了. #include<cstdio> #include<cstring> #define MT 65533*4 #define Maxn MT*4 int ...

  7. Centos 下Nginx 自启动脚本

    #!/bin/bash #ckconfig: NGINX_PATH=/web/container/nginx- NGINX_COMMAND=$NGINX_PATH/sbin/nginx NGINX_P ...

  8. DbHelper and OracleHelper

    1 连接Sql Server的ConnectionString: Data Source=.;Initial Catalog=ViewVideo;User ID=sa;Password=XXXXXX; ...

  9. NGINX(三)HASH表

    前言 nginx的hash表有几种不同的种类, 不过都是以ngx_hash_t为基础的, ngx_hash_t是最普通的hash表, 冲突采用的是链地址法, 不过这里冲突的元素不是一个链表, 而是一个 ...

  10. 【JMeter】Jmeter引入第三方jar包

    Jmeter做remoteService,里面用到一个实体:clickEntity,是在一个第三方jar包定义的:com.bj58.opt.ad_logparser-0.0.18-SNAPSHOT.j ...