#include<cstdio>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<queue>
#include<iostream>
using namespace std;
const int maxn=2e5+;
int ary[maxn];
struct node
{
int l,r,val;
}tree[maxn<<];
void push_up(int cur)
{
tree[cur].val=max(tree[cur*].val,tree[cur*+].val);
}
void build(int l,int r,int cur)
{
tree[cur].l=l,tree[cur].r=r;
tree[cur].val=;
if(l==r){
tree[cur].val=ary[l];
return;
}
int mid=(l+r)/;
build(l,mid,cur*);
build(mid+,r,cur*+);
push_up(cur);
}
int query(int l,int r,int cur)
{ if(l<=tree[cur].l&&r>=tree[cur].r)
return tree[cur].val;
int mid=(tree[cur].l+tree[cur].r)/;
int ans=;
if(l<=mid) ans=max(ans,query(l,r,cur*));
if(r>mid) ans=max(ans,query(l,r,cur*+));
return ans;
}
void Update(int base,int price,int cur)
{
if(tree[cur].l==tree[cur].r){
tree[cur].val=price;
return;
}
int mid=(tree[cur].l+tree[cur].r)/;
if(base<=mid) Update(base,price,cur*);
else Update(base,price,cur*+);
push_up(cur);
}
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
for(int i=;i<=n;i++) scanf("%d",&ary[i]);
build(,n,);
while(m--){
char tmp;
cin>>tmp;
if(tmp=='Q'){
int l,r;
scanf("%d%d",&l,&r);
int ans=query(l,r,);
printf("%d\n",ans);
}
else{
int l,r;
scanf("%d%d",&l,&r);
Update(l,r,);
}
}
}
return ;
}

线段树 区间查询最大值,单体修改 hdu 1754的更多相关文章

  1. ACM_3n+1问题(克拉兹问题+线段树区间查询最大值)

    3n+1问题 Time Limit: 2000/1000ms (Java/Others) Problem Description: 考虑如下的序列生成算法:从整数n开始,如果n是偶数,把它除以2:如果 ...

  2. 最大数maxnumber (HYSBZ 1012)(线段树区间查询和单点修改)(优雅的暴力)

    Problem 现在请求你维护一个数列,要求提供以下两种操作:1. 查询操作.语法:Q L 功能:查询当前数列中末尾L 个数中的最大的数,并输出这个数的值.限制:L不超过当前数列的长度.2. 插入操作 ...

  3. Light OJ-1082 - Array Queries,线段树区间查询最大值,哈哈,水过~~

                                                                                                        ...

  4. 约会安排 HDU - 4553(线段树区间查询,区间修改,区间合并)

    题目: 寒假来了,又到了小明和女神们约会的季节.  小明虽为屌丝级码农,但非常活跃,女神们常常在小明网上的大段发言后热情回复“呵呵”,所以,小明的最爱就是和女神们约会.与此同时,也有很多基友找他开黑, ...

  5. (线段树 区间查询)The Water Problem -- hdu -- 5443 (2015 ACM/ICPC Asia Regional Changchun Online)

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=5443 The Water Problem Time Limit: 1500/1000 MS (Java/ ...

  6. HDU 1754 I Hate It(线段树区间查询,单点更新)

    描述 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感.不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问.当然,老 ...

  7. HDU.5692 Snacks ( DFS序 线段树维护最大值 )

    HDU.5692 Snacks ( DFS序 线段树维护最大值 ) 题意分析 给出一颗树,节点标号为0-n,每个节点有一定权值,并且规定0号为根节点.有两种操作:操作一为询问,给出一个节点x,求从0号 ...

  8. POJ_3468 A Simple Problem with Integers 【线段树区间查询+修改】

    一.题目 POJ3468 二.分析 裸的线段树区间查询+修改. 三.AC代码 #include <cstdio> #include <iostream> #include &l ...

  9. POJ 3264 Balanced Lineup【线段树区间查询求最大值和最小值】

    Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 53703   Accepted: 25237 ...

随机推荐

  1. python接口自动化之pytest环境准备与入门(五)

    安装的pytest版本应该与安装的python版本对应,不然会有问题 (我的环境是python3.6与pytest4.5.0) 1.安装pytest pip install pytest==4.5.0 ...

  2. eclipse中配置maven环境

    一.配置setting.xml文件 1.首先将下载好的maven打开,打开文件夹,首先就需要对maven安装目录下有个config文件夹,在文件夹下有settings.xml文件.settings里面 ...

  3. Codeforce 230A - Dragons (sort)

    Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defe ...

  4. 关于Oracle的使用

    1.查看数据库 在sqlplus / as sysdba执行后,再执行select name from v$database; 2.执行1后继续查看该数据库下的表 select table_name ...

  5. 如何在macOS下安装geoserver

    macOS 下的编译包 如果是使用安装文件,请查看官网文档,如果想要部署在已有的tomcat服务下,请查看网页压缩包章节. Web archive. An alternate way of insta ...

  6. PP: Neural ordinary differential equations

    Instead of specifying a discrete sequence of hidden layers, we parameterize the derivative of the hi ...

  7. 移动端调试神器vConsole

    vConsole.js 其实就是重写console方法,实现了类似于微信小程序的移动端调试效果 在普通html文件里使用 <script src="https://cdn.bootcs ...

  8. JS高级---复习和课程介绍

    课程介绍 浅拷贝 深拷贝----------|======>递归 遍历DOM树-------|======>递归------晚上能够把代码写出来是最好的   正则表达式-------很重要 ...

  9. selenium爬去数据+存储

    1 爬去数据代码 #coding=utf-8 from selenium import webdriver from selenium.webdriver.common.by import By fr ...

  10. 动图演示23个鲜为人知的VSCode快捷键

    动图演示23个鲜为人知的VSCode快捷键 原文地址:dev.to/devmount/23… 代码同步浏览器 安装vccode 安装live server插件 尽管我在VS Code中经常使用许多快捷 ...