HDU 1754 I Hate It 线段树 单点更新 区间最大值
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<stack>
#include<cmath>
#include<queue>
#include <bits/stdc++.h>
using namespace std; int MAX[];
//int max(int a,int b)
//{
// return a>b?a:b;
//}
void pushup(int rt)
{
MAX[rt]=max(MAX[rt<<],MAX[(rt<<)+]);
}
void build(int l,int r,int rt)
{
if(l==r)
{
scanf("%d",&MAX[rt]);
return;
}
int m=(l+r)>>;
build(l,m,rt<<);
build(m+,r,(rt<<)+);
pushup(rt);
}
void update(int p,int q,int l,int r,int rt)
{
if(l==r)
{
MAX[rt]=q;
return;
}
int m=(l+r)>>;
if(p<=m)
update(p,q,l,m,rt<<);
else
update(p,q,m+,r,(rt<<)+);
pushup(rt);
}
int getmax(int L,int R,int l,int r,int rt)
{
if(L<=l&&r<=R)
return MAX[rt];
int m=(r+l)>>;
int ret=;
if(L<=m)
ret=max(ret,getmax(L,R,l,m,rt<<));
if(R>m)
ret=max(ret,getmax(L,R,m+,r,(rt<<)+));
return ret;
}
int main()
{
int n,m,a,b,i;
char c;
while(~scanf("%d %d",&n,&m))
{
build(,n,);
for(i=; i<m; i++)
{
scanf("%*c%c%d %d",&c,&a,&b);//*c与getchar一样
if(c=='Q')
printf("%d\n",getmax(a,b,,n,));
else
update(a,b,,n,);
}
}
return ;
}
HDU 1754 I Hate It 线段树 单点更新 区间最大值的更多相关文章
- HDU 1754 I Hate It 线段树单点更新求最大值
题目链接 线段树入门题,线段树单点更新求最大值问题. #include <iostream> #include <cstdio> #include <cmath> ...
- hdu 1754 I Hate It 线段树 单点更新 区间最值
线段树功能:update:单点更新 query:区间最值 #include <bits/stdc++.h> #define lson l, m, rt<<1 #define r ...
- HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对)
HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对) 题意分析 给出n个数的序列,a1,a2,a3--an,ai∈[0,n-1],求环序列中逆序对 ...
- HDU 1754 I Hate It(线段树单点替换+区间最值)
I Hate It [题目链接]I Hate It [题目类型]线段树单点替换+区间最值 &题意: 本题目包含多组测试,请处理到文件结束. 在每个测试的第一行,有两个正整数 N 和 M ( 0 ...
- 【HDU】1754 I hate it ——线段树 单点更新 区间最值
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 1754 I Hate It 线段树(单点更新,成段查询)
题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=1754 题解: 单点更新,成段查询. 代码: #include<iostream> ...
- HDU-1754-I Hate It(线段树 单点更新 区间最大值)
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU.1166 敌兵布阵 (线段树 单点更新 区间查询)
HDU.1166 敌兵布阵 (线段树 单点更新 区间查询) 题意分析 加深理解,重写一遍 代码总览 #include <bits/stdc++.h> #define nmax 100000 ...
- hdu 1166线段树 单点更新 区间求和
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
随机推荐
- CentOS 编译安装Apache2.4.10
1.准备编译环境 yum -y install gcc make cmake autoconf libtool libevent 安装apache必须的依赖包 yum -y install apr-u ...
- 【pyhton】【转】修改递归次数
import sys sys.setrecursionlimit(1500) # set the maximum depth as 1500 def recursion(n): if(n <= ...
- 【原创】一起学C++ 之 字符串 ---------C++ primer plus(第6版)
C++ Primer Plus 第6版 字符串:是存储在内存的连续字节中的一系列字符. C++处理字符串的方式有2种: 一.来自C语言.常被称为C-风格字符串(C-Style-string) 1)从字 ...
- makefile的简单写法
makefile 使用方法: vi 一个Makefile文件 CC = g++ // 指的是用什么编译器RM = rm -rf // 定义一个删除的指令(变量)CFLAGS = -c -Wal ...
- ireport 在 AIX Linux websphere下的字体安装
首先,ireport在linux下有些时候是正常的,而有些时候却不正常,只要是汉字就出不来的情况我今天是遇到了. ireport在Linux下不显示中文汉字的解决方法: 将字体文件(后缀名必须是ttf ...
- Windows下虚拟Linux
andlinux cygwin virtualbox VMware XenServer
- win7系统64位eclipse环境超详细暗黑1.4服务器搭建
原地址:http://bbs.gameres.com/thread_223704.html 今天闲来没事,参照论坛中几篇成功案例,自己也搭建了下服务端,这里详细的记录下我的安装过程,方便大家快速搭建. ...
- linux0.11下的中断机制分析
http://orbt.blog.163.com/ 异常就是控制流中的突变,用来响应处理器状态中的某些变化.当处理器检测到有事件发生时,它就会通过一张叫做异常表的跳转表,进行一个间接过程调用, ...
- VMware与宿敌Amazon一笑泯恩仇:重新定义混合云?(私有云节节败退)
摘要: 私有云巨头VMware看来是真的要输给一个“书贩子” 了!这意味着私有云将败给公有云? [阅读原文] 三年前,虚拟化巨头VMware曾对亚马逊Amazon云服务AWS竖过中指:我们怎么可能打不 ...
- WPF 3D 小小小小引擎 - ·WPF 3D变换应用
原文:WPF 3D 小小小小引擎 - ·WPF 3D变换应用 WPF可以提供的3D模型使我们可以轻松地创建3D实体,虽然目前来看还很有一些性能上的问题,不过对于一些简单的3D应用应该是可取的,毕竟其开 ...