线段树点修改  区间最大值查询

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <string>
#include <cstring>
#include <algorithm>
#include <iostream>
#define maxn 200010
#define INF 0x7fffffff
#define inf 10000000
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
using namespace std; int n, m, maxv[maxn*2], a[maxn], p, v, ql, qr; void build(int id, int L, int R)
{
if(L == R) maxv[id] = a[L];
else
{
int M = L + (R-L)/2;
build(id*2, L, M);
build(id*2+1, M+1, R);
maxv[id] = max(maxv[id*2], maxv[id*2+1]);
}
} void update(int id, int L, int R)
{
if(L == R) maxv[id] = v;
else
{
int M = L + (R-L)/2;
if(p <= M) update(id*2, L, M);
else update(id*2+1, M+1, R);
maxv[id] = max(maxv[id*2], maxv[id*2+1]);
}
} int query(int id, int L, int R)
{
int M = L + (R-L)/2, ans = 0;
if(ql <= L && qr >= R) return maxv[id];
if(ql <= M) ans = max(ans, query(id*2, L, M));
if(qr > M) ans = max(ans, query(id*2+1, M+1, R));
return ans;
} int main()
{
while(scanf("%d%d", &n, &m) == 2)
{
memset(maxv, 0, sizeof(maxv));
for(int i = 1; i <= n; ++ i) scanf("%d", &a[i]);
build(1, 1, n);
//getchar();
for(int i = 0; i < m; ++ i)
{
getchar();
char c = getchar();
if(c == 'Q')
{
scanf("%d%d", &ql, &qr);
printf("%d\n", query(1, 1, n));
}
else if(c == 'U')
{
scanf("%d%d", &p, &v);
update(1, 1, n);
}
}
}
return 0;
}

hdu 1754 线段树入门的更多相关文章

  1. HDU 1754 线段树入门解题报告

    ---恢复内容开始--- 题意:给定区间,每个人的成绩, Q次询问,求每次询问区间中的最大值 思路:构造线段树 代码: #include<stdio.h> #include<algo ...

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

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

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

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

  4. HDU 1754线段树基本操作,建树,更新,查询

    代码线段树入门整理中有介绍. #include<cstdio> #include<algorithm> #include<cstring> #include< ...

  5. HDU 1754 线段树 单点跟新 HDU 1166 敌兵布阵 线段树 区间求和

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

  6. HDU - 1754 线段树-单点修改+询问区间最大值

    这个也是线段树的经验问题,待修改的,动态询问区间的最大值,只需要每次更新的时候,去把利用子节点的信息进行修改即可以. 注意更新的时候区间的选择,需要对区间进行二分. #include<iostr ...

  7. hdu 1754 线段树(单点替换 区间最值)

    Sample Input5 61 2 3 4 5Q 1 5 //1-5结点的最大值U 3 6 //将点3的数值换成6Q 3 4Q 4 5U 2 9Q 1 5 Sample Output5659 # i ...

  8. HDU 1754线段树

    第一个自己动手写的线段树,1Y还是有点小激动哈(虽然是模版题) 1 #include<cstdio> 2 #include<cstring> 3 #include<alg ...

  9. hdu 1754 线段树模板题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754 #include <cstdio> #include <cmath> # ...

随机推荐

  1. 多文件上传artDialog+plupload

    一.效果展示 包括文件上传面板以及文件上传列表 二.介绍 长话短说,采用spring springMVC mybatis maven mysql,实现多文件上传功能,下载使用的是流的形式. 其中涉及的 ...

  2. ionic项目相关的操作命令

     更新npmD:\Program Files\npm-3.9.0\npmnode cli.js install npm -gf vs安装 更新node.js  windows版直接从官网下载安装包 n ...

  3. mybatis 聚合查询

    <resultMap id="ExtResultMap" type="com.demo.partner.po.PartnerPO"> <id ...

  4. Linux 线程 条件变量

    一:条件变量 直接上最基本的两个函数,先抓主要矛盾: //等待条件 int pthread_cond_wait(pthread_cond_t *restrict cond, pthread_mutex ...

  5. 获取Class对象的方法及Class类型的一些讨论

    (1)Class.forName(className) (2)classname.Class 如果是数组,则是数组类型[].class (3)对象.getClass() 例: String path ...

  6. linux 安装sysstat使用iostat、mpstat、sar、sa(转载)

    使用yum安装 #yum install sysstat sysstat的安装包是:sysstat-5.0.5-1.i386.rpm,装完了sysstat-5.0.5-1.i386.rpm后 就会有i ...

  7. 例题6-4 Broken Keyboard UVa11988

    题目分析: 起初这道题目没有做出来,原因是我一直想把整块区域一并插入,而不是逐个插入.今后做题应该注意这个问题,把问题分解去考虑,也许会少走许多弯路. 下边附上AC代码 #include <cs ...

  8. Stanford parser学习:LexicalizedParser类分析

    上次(http://www.cnblogs.com/stGeekpower/p/3457746.html)主要是对应于javadoc写了下LexicalizedParser类main函数的功能,这次看 ...

  9. WPF中的DataTemplate

    <Window x:Class="DateTemplate应用.MainWindow" xmlns="http://schemas.microsoft.com/wi ...

  10. 博主教你制作类似9patch效果的iOS图片拉伸

    下面张图片,本来是设计来做按钮背景的:   button.png,尺寸为:24x60 现在我们把它用作为按钮背景,按钮尺寸是150x50: // 得到view的尺寸 CGSize viewSize = ...