题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754

 #include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <queue>
#include <vector> #define maxn 230050
#define lson l,mid,u<<1
#define rson mid+1,r,u<<1|1
using namespace std; const int INF = 0x3f3f3f; int seg[maxn<<]; int Push_UP(int u){
seg[u] = max(seg[u<<],seg[u<<|]); //****这个地方 u<<1|1 不能换为 u << 1 +1
}
void build(int l,int r,int u){
if(l == r){
scanf("%d",&seg[u]);
return;
}
int mid = (l + r)/;
build(lson);
build(rson);
Push_UP(u);
}
void Update(int loc,int num,int l,int r,int u){
if(l == r){ // 这个地方要注意!!
seg[u] = num;
return;
}
int mid = (l + r)/;
if(loc <= mid) Update(loc,num,lson);
else Update(loc,num,rson);
Push_UP(u);
}
int Query(int L,int R,int l,int r,int u){
if(L <= l && r <= R){
return seg[u];
}
int ret = ;
int mid = (l + r)/;
if(L <= mid) ret =max(ret,Query(L,R,lson));
if(R > mid) ret =max(ret,Query(L,R,rson));
return ret;
}
int main()
{
if(freopen("input.txt","r",stdin)== NULL) {printf("Error\n"); exit();}
int N,M;
while(cin>>N>>M){
build(,N,);
while(M--){
char query[];
int l,r;
scanf("%s%d%d",query,&l,&r);
if(query[] == 'U') Update(l,r,,N,);
else{
int ans = Query(l,r,,N,);
printf("%d\n",ans);
}
}
}
}

hdu 1754 线段树模板题的更多相关文章

  1. hdu 1754 线段树 水题 单点更新 区间查询

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  2. HDU(1754),线段树,单点替换,区间最值

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754 线段树模板题,update功能是单点替换,query是访问区间最大值. #include < ...

  3. HDU 1698 Just a Hook (线段树模板题-区间求和)

    Just a Hook In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of t ...

  4. [AHOI 2009] 维护序列(线段树模板题)

    1798: [Ahoi2009]Seq 维护序列seq Time Limit: 30 Sec  Memory Limit: 64 MB Description 老师交给小可可一个维护数列的任务,现在小 ...

  5. hdu 1754 线段树(Max+单点修改)

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  6. hdu1823(二维线段树模板题)

    hdu1823 题意 单点更新,求二维区间最值. 分析 二维线段树模板题. 二维线段树实际上就是树套树,即每个结点都要再建一颗线段树,维护对应的信息. 一般一维线段树是切割某一可变区间直到满足所要查询 ...

  7. [POJ2104] 区间第k大数 [区间第k大数,可持久化线段树模板题]

    可持久化线段树模板题. #include <iostream> #include <algorithm> #include <cstdio> #include &l ...

  8. HDU 1251 Trie树模板题

    1.HDU 1251 统计难题  Trie树模板题,或者map 2.总结:用C++过了,G++就爆内存.. 题意:查找给定前缀的单词数量. #include<iostream> #incl ...

  9. UESTC - 1057 秋实大哥与花 线段树模板题

    http://acm.uestc.edu.cn/#/problem/show/1057 题意:给你n个数,q次操作,每次在l,r上加上x并输出此区间的sum 题解:线段树模板, #define _CR ...

随机推荐

  1. Tomcat下work文件夹的作用

    1.打补丁,重启tomcat时要删除work文件夹,有缓存. 2.work目录只是tomcat的工作目录,也就是tomcat把jsp转换为class文件的工作目录 jsp,tomcat的工作原理: 当 ...

  2. oracle 数据库关闭的的几种方式总结

    shutdown的几种方式,shutdown abort的一些弊端有哪些   1.shutdown normal        正常方式关闭数据库.    2.shutdown immediate   ...

  3. 【转】 NSString什么时候用copy,什么时候用strong

    原文: http://blog.csdn.net/itianyi/article/details/9018567 大部分的时候NSString的属性都是copy,那copy与strong的情况下到底有 ...

  4. 一条sql语句循环插入N条不同记录(转)

    SET NOCOUNT ON IF (OBJECT_ID('TB' ) IS NOT NULL ) DROP TABLE TB GO CREATE TABLE TB(ID INT IDENTITY ( ...

  5. 英语学习[ZZ]

    本文作者三年间从四级勉强及格到高级口译笔试210,口试232.找工作面试时给其口试的老外考官听了一分钟就说你的英语不用考了.虽不敢说方法一定是最好的,但从现在开始随便谁不要再去找学习资料,每天花两个钟 ...

  6. C#中Predicate的一点理解

    本人喜欢代码看起来比较优雅,而C#真的是一种很优雅的语言.比如我们New List<string> StrList; 如果我们想查找StrList,可以使用C#提供的 StrList.Fi ...

  7. 不使用ASP.NET服务器端控件(包括form表单不加runat="server")来触发.cs里的事件(方法),(适用于有代码洁癖者)。

    很多时候,我们使用服务器端控件写出的代码,会给我们生成一些很多我们看不懂的代码(初学者),但是有时候我们并不需要这些代码(业务需求不同),对于生成的一些代码感到多余.所以我就开始想,有没有一种可能:不 ...

  8. sphinx (coreseek)——3、区段查询 与 增量索引实例

    首先本文测试数据100多万的域名的wwwtitle 信息  检索数据: 首先建立临时表格: CREATE TABLE `sph_counter` ( `index_id` ) NOT NULL, `m ...

  9. openerp 报表字段 report_rml_content_data

    按需求修改一个报表,本想按照打印出来的报表内容搜索rml文件,找到需要修改的rml问加. 但是发现搜索不到,后来查询报表动作,确认对应的rml文件中,没有发现 “报表中” 的字串. 猜测可能是rml直 ...

  10. Notepad++插件之FingerText

    FingerText是一个标签触发片段插件记事本.支持多个热点同时编辑,嵌套的热点,动态热点(很多不仅仅是纯文本的,可以通过命令,或触发另一个片段中的片段),热点的文本提示(而不是仅仅是$或#号)和热 ...