http://www.notonlysuccess.com/index.php/segment-tree-complete/

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define maxn 2222222
using namespace std;
int a[maxn<<2];
void pushUp(int rt)
{
a[rt]=max(a[rt<<1],a[rt<<1|1]);
}
void build(int l,int r,int rt)
{
if(l==r)
{
scanf("%d",&a[rt]);
return ;
}
int m=(r+l)>>1;
build(lson);
build(rson);
pushUp(rt);
}
void update(int p,int sc,int l,int r,int rt)
{
if(l==r)
{
a[rt]=sc;
return;
}
int m=(l+r)>>1;
if(p<=m) update(p,sc,lson);
else update(p,sc,rson);
pushUp(rt);
}
int query(int L,int R,int l,int r,int rt)
{
int x=0;
if(L<=l&&r<=R)
return a[rt];
int m=(r+l)>>1;
if(L<=m) x=max(x,query(L,R,lson));
if(R>m) x=max(x,query(L,R,rson));
return x;
}
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
build(1,n,1);
char c[2];
int d,e;
for(int i=0; i<m; i++)
{
scanf("%s%d%d",c,&d,&e);
if(c[0]=='Q')
{
printf("%d\n",query(d,e,1,n,1));
}
if(c[0]=='U')
{
update(d,e,1,n,1);
}
}
}
return 0;
}

hdu_1754,线段树单点更新,求区间最值的更多相关文章

  1. HDU 2795 Billboard (线段树单点更新 && 求区间最值位置)

    题意 : 有一块 h * w 的公告板,现在往上面贴 n 张长恒为 1 宽为 wi 的公告,每次贴的地方都是尽量靠左靠上,问你每一张公告将被贴在1~h的哪一行?按照输入顺序给出. 分析 : 这道题说明 ...

  2. HDU 1754 I Hate It 线段树单点更新求最大值

    题目链接 线段树入门题,线段树单点更新求最大值问题. #include <iostream> #include <cstdio> #include <cmath> ...

  3. poj 2892---Tunnel Warfare(线段树单点更新、区间合并)

    题目链接 Description During the War of Resistance Against Japan, tunnel warfare was carried out extensiv ...

  4. 计蒜客 28315.Excellent Engineers-线段树(单点更新、区间最值) (Benelux Algorithm Programming Contest 2014 Final ACM-ICPC Asia Training League 暑假第一阶段第二场 E)

    先写这几道题,比赛的时候有事就只签了个到. 题目传送门 E. Excellent Engineers 传送门 这个题的意思就是如果一个人的r1,r2,r3中的某一个比已存在的人中的小,就把这个人添加到 ...

  5. HDU 1394 Minimum Inversion Number (线段树 单点更新 求逆序数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394 题意:给你一个n个数的序列,当中组成的数仅仅有0-n,我们能够进行这么一种操作:把第一个数移到最 ...

  6. hdoj 2795 Billboard 【线段树 单点更新 + 维护区间最大值】

    Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  7. BZOJ 1012: [JSOI2008]最大数maxnumber【线段树单点更新求最值,单调队列,多解】

    1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 10374  Solved: 4535[Subm ...

  8. HDU 1754.I Hate It-完全版线段树(单点替换、区间最值)

    HDU1754.I Hate It 直接模板就可以了 代码: //B #include<iostream> #include<cstdio> #include<cstri ...

  9. nyoj 568——RMQ with Shifts——————【线段树单点更新、区间求最值】

    RMQ with Shifts 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述     In the traditional RMQ (Range Minimum Q ...

  10. hdu 1754 线段树 单点更新 动态区间最大值

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

随机推荐

  1. [terry笔记]GoldenGate_迁移同步_主库零停机

    ogg根据scn同步数据,源库零停机时间 本次实验与上次的区别:更加注重细节,几乎包含所有步骤,把我越到的坑都作出了说明.并且同步是由10g向11g进行同步,更加符合升级迁移需求. 如下是主要步骤: ...

  2. java内存管理之内存模型

    1,运行时数据区域 1. 程序计数器 (program counter register) 2. Java虚拟机栈 (jvm stack) 3. 本地方法栈 (native method stack) ...

  3. [TS] Class Properties Public, Private and Read Only Modifiers

    In the constructor, we want to set the prop to readonly, you need to do like this: class Superhero { ...

  4. CC2540/CC2541 : Set the Peripheral Being Advertising while It is Being Connected

    There is possible to set your CC254X be scanable when it is in connection. But, based on my test,the ...

  5. ZOJ Problem Set - 3820 Building Fire Stations 【树的直径 + 操作 】

    题目:problemId=5374" target="_blank">ZOJ Problem Set - 3820 Building Fire Stations 题 ...

  6. Mosquito的优化——epoll优化(七)

    本文由逍遥子撰写,转发请标注原址: http://blog.csdn.net/houjixin/article/details/46413583 或 http://houjixin.blog.163. ...

  7. 安装Oracle RAC 11g

    1.Oracle Enterprise Linux 和 iSCSI 上构建 Oracle RAC 11g 集群 2.Oracle RAC 的所有共享磁盘存储将基于 iSCSI,iSCSI 使用在第三个 ...

  8. oracle rac 巡检过程详解

    一 RAC环境 RAC架构,2节点信息 节点1 SQL> show parameter instance NAME                                 TYPE    ...

  9. 《汇编语言(第三版)》pushf 和 popf 指令,以及标志寄存器在 Debug 中的表示

    pushf 和 popf pushf 的功能是将标志寄存器的值压栈,而 popf 是从栈中弹出数据,输入标志寄存器. pushf 和 popf,为直接访问寄存器提供了方法. 格式 pushf popf ...

  10. ZOJ 3321 Circle【并查集】

    解题思路:给定n个点,m条边,判断是否构成一个环 注意到构成一个环,所有点的度数为2,即一个点只有两条边与之相连,再有就是判断合并之后这n个点是否在同一个连通块 Circle Time Limit: ...