http://acm.hdu.edu.cn/showproblem.php?pid=1754

单点更新,区间求最值

// File Name: hdu1754.cpp
// Author: bo_jwolf
// Created Time: 2013年08月16日 星期五 11点27分03秒 #include<vector>
#include<list>
#include<map>
#include<set>
#include<deque>
#include<stack>
#include<bitset>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<ctime> using namespace std; #define lson l , mid , rt << 1
#define rson mid + 1 , r , rt << 1 | 1 const int maxn = 200005 ;
//int sum[ maxn << 2 ] ; struct node
{
int Max ;
}tree[ maxn << 2 ] ; void PushUp( int rt )
{
tree[ rt ].Max = max( tree[ rt << 1 ].Max , tree[ (rt << 1 | 1 ) ].Max ) ;
}
void build( int l , int r , int rt )
{
if( l == r )
{
scanf( "%d" , &tree[ rt ].Max );
return ;
}
int mid = ( l + r ) >> 1 ;
build( lson ) ;
build( rson ) ;
PushUp( rt ) ;
} void update( int p , int add , int l , int r , int rt )
{
if( l == r )
{
tree[ rt ].Max = add ;
return ;
}
int mid = ( l + r ) >> 1 ;
if( p <= mid )
update( p , add , lson ) ;
else
update( p , add , rson ) ;
PushUp( rt ) ;
} int query( int L , int R , int l , int r , int rt )
{
if( L <= l && r <=R )
{
return tree[ rt ].Max ;
}
int mid = ( l + r ) >> 1 ;
int ret = 0 ;
if( L <= mid )
ret = max( ret , query( L , R , lson ) ) ;
if( R > mid )
ret = max( ret , query( L , R , rson ) );
return ret ;
} int main()
{
int T , n , m ;
while( scanf( "%d%d" , &n , &m ) != EOF )
{
build( 1 , n , 1 ) ;
char op[ 10 ] ;
while( m-- )
{
scanf( "%s" , op ) ;
int a , b ;
scanf( "%d%d" , &a , &b ) ;
if( op[ 0 ] == 'Q' )
printf( "%d\n" , query( a , b , 1 , n , 1 ) ) ;
else
update( a , b , 1 , n , 1 ) ;
}
}
return 0;
}

hdu1753I Hate It(线段树)的更多相关文章

  1. bzoj3932--可持久化线段树

    题目大意: 最近实验室正在为其管理的超级计算机编制一套任务管理系统,而你被安排完成其中的查询部分.超级计算机中的 任务用三元组(Si,Ei,Pi)描述,(Si,Ei,Pi)表示任务从第Si秒开始,在第 ...

  2. codevs 1082 线段树练习 3(区间维护)

    codevs 1082 线段树练习 3  时间限制: 3 s  空间限制: 128000 KB  题目等级 : 大师 Master 题目描述 Description 给你N个数,有两种操作: 1:给区 ...

  3. codevs 1576 最长上升子序列的线段树优化

    题目:codevs 1576 最长严格上升子序列 链接:http://codevs.cn/problem/1576/ 优化的地方是 1到i-1 中最大的 f[j]值,并且A[j]<A[i] .根 ...

  4. codevs 1080 线段树点修改

    先来介绍一下线段树. 线段树是一个把线段,或者说一个区间储存在二叉树中.如图所示的就是一棵线段树,它维护一个区间的和. 蓝色数字的是线段树的节点在数组中的位置,它表示的区间已经在图上标出,它的值就是这 ...

  5. codevs 1082 线段树区间求和

    codevs 1082 线段树练习3 链接:http://codevs.cn/problem/1082/ sumv是维护求和的线段树,addv是标记这歌节点所在区间还需要加上的值. 我的线段树写法在运 ...

  6. PYOJ 44. 【HNSDFZ2016 #6】可持久化线段树

    #44. [HNSDFZ2016 #6]可持久化线段树 统计 描述 提交 自定义测试 题目描述 现有一序列 AA.您需要写一棵可持久化线段树,以实现如下操作: A v p x:对于版本v的序列,给 A ...

  7. CF719E(线段树+矩阵快速幂)

    题意:给你一个数列a,a[i]表示斐波那契数列的下标为a[i],求区间对应斐波那契数列数字的和,还要求能够维护对区间内所有下标加d的操作 分析:线段树 线段树的每个节点表示(f[i],f[i-1])这 ...

  8. 【BZOJ-3779】重组病毒 LinkCutTree + 线段树 + DFS序

    3779: 重组病毒 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 224  Solved: 95[Submit][Status][Discuss] ...

  9. 【BZOJ-3673&3674】可持久化并查集 可持久化线段树 + 并查集

    3673: 可持久化并查集 by zky Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 1878  Solved: 846[Submit][Status ...

  10. 【BZOJ-2653】middle 可持久化线段树 + 二分

    2653: middle Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 1298  Solved: 734[Submit][Status][Discu ...

随机推荐

  1. 51nod1437 迈克步

    傻叉单调栈 #include<cstdio> #include<cstring> #include<cctype> #include<algorithm> ...

  2. Asp.Net验证码3

    using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System. ...

  3. C语言之复杂指针详解

    在<C陷阱与缺陷>第二章第一节中有这样一个声明: (*(void(*)())0)(): 看到这样的表达式估计让不少人都“不寒而栗”了吧,其实虽然看起来复杂,但是构造这类表达式其实只有一条简 ...

  4. BZOJ 1123 BLO

    tarjan求割点计算答案.注意不是每一棵子树都算答案.开个变量记一下. #include<iostream> #include<cstdio> #include<cst ...

  5. HDU pog loves szh II (数的处理)

    题意: 给一个序列,找出两个数字a和b(可以相等但不可相同),要求(a+b)%p的结果最大. 思路: 先将所有元素模p,再排序.要找出a和b,分两种情况,a+b>p和a+b<p.第一种,肯 ...

  6. erl_0013 erlang 带参数模块 parameterized modules are no longer supported

    code: -module(mod_test, [Name]). -export([show/0]). show() -> io:format("show:~p~n",[Na ...

  7. Ensemble Learning 之 Bagging 与 Random Forest

    Bagging 全称是 Boostrap Aggregation,是除 Boosting 之外另一种集成学习的方式,之前在已经介绍过关与 Ensemble Learning 的内容与评价标准,其中“多 ...

  8. PHP实现站点pv,uv统计(三)

    数据分析脚本如下: //error_reporting(0);date_default_timezone_set("PRC");$environment = get_cfg_var ...

  9. 使用 Linux 终端 SSH 登录 VPS

    Windows 中远程 SSH 登录 VPS 进行管理的利器是 PuTTY,但是 Linux 中就没必要用它了.Linux.Unix(包括 Mac iOS)都必然有内置的命令行终端,内建了 OpenS ...

  10. mysql 查看所有存储过程

    转载地址:http://zhuixue.iteye.com/blog/375353 查询数据库中的存储过程 方法一: select `name` from mysql.proc where db = ...