hdu 1754 线段树模板题
题目链接: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 线段树模板题的更多相关文章
- hdu 1754 线段树 水题 单点更新 区间查询
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU(1754),线段树,单点替换,区间最值
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754 线段树模板题,update功能是单点替换,query是访问区间最大值. #include < ...
- 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 ...
- [AHOI 2009] 维护序列(线段树模板题)
1798: [Ahoi2009]Seq 维护序列seq Time Limit: 30 Sec Memory Limit: 64 MB Description 老师交给小可可一个维护数列的任务,现在小 ...
- hdu 1754 线段树(Max+单点修改)
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- hdu1823(二维线段树模板题)
hdu1823 题意 单点更新,求二维区间最值. 分析 二维线段树模板题. 二维线段树实际上就是树套树,即每个结点都要再建一颗线段树,维护对应的信息. 一般一维线段树是切割某一可变区间直到满足所要查询 ...
- [POJ2104] 区间第k大数 [区间第k大数,可持久化线段树模板题]
可持久化线段树模板题. #include <iostream> #include <algorithm> #include <cstdio> #include &l ...
- HDU 1251 Trie树模板题
1.HDU 1251 统计难题 Trie树模板题,或者map 2.总结:用C++过了,G++就爆内存.. 题意:查找给定前缀的单词数量. #include<iostream> #incl ...
- UESTC - 1057 秋实大哥与花 线段树模板题
http://acm.uestc.edu.cn/#/problem/show/1057 题意:给你n个数,q次操作,每次在l,r上加上x并输出此区间的sum 题解:线段树模板, #define _CR ...
随机推荐
- eclipse alt + '/' not working.
searching for google,I observed that the 'content assist' shortcut key was take placed with 'ctrl + ...
- NRPE: Unable to read output 问题处理总结
自定义nagios监控命令check_disk_data,首先在nagios服务端command.cfg定义了#'check_disk_data' command definitiondefine c ...
- sql uniqueidentifier转varchar
--- DECLARE @myid uniqueidentifierSET @myid = NEWID()SELECT CONVERT(char(255), @myid) AS 'char';GO-- ...
- iframe的缺点与优点?
iframe是一种框架,也是一种很常见的网页嵌入方式. iframe的优点: iframe能够原封不动的把嵌入的网页展现出来. 如果有多个网页引用iframe,那么你只需要修改iframe的内容,就可 ...
- 输出内容(document.write)
document.write() 直接在页面中输出内容 第一种 直接输出 document.write("I Love Javascript !") //输出内容为:I Love ...
- 十大算法---Adaboost
当我们有针对同一数据集有多个不同的分类器模型时,怎样组合它们使预测分类的结果更加准确, 针对这种情况,机器学习通常两种策略. 1 一种是bagging,一种是boosting bagging:随机对样 ...
- [LeetCode OJ]-Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- javascript——迭代方法
<script type="text/javascript"> //五个迭代方法 都接受两个参数:要在每一项上运行的函数 和 运行该函数的作用域(可选) //every ...
- ie11下,插入框架Html
if(navigator.userAgent.indexOf("MSIE")>0 || (navigator.userAgent.indexOf("Trident& ...
- [jQuery编程挑战]004 针对选择框词典式排序
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="utf-8&quo ...