题意:给出n个数,每次操作修改它的第s个数,询问给定区间的数的最大值

把前面两道题结合起来就可以了

自己还是敲不出来-------------

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=; int n,m;
int a[maxn];
int nmax; struct node{
int l,r;
int nmax;
} tree[*maxn]; char s[]; void build_tree(int i,int l,int r){
tree[i].l=l;
tree[i].r=r;
if(l==r){
tree[i].nmax=a[l];
return;
}
int mid=(l+r)/;
build_tree(*i,l,mid);
build_tree(*i+,mid+,r);
tree[i].nmax=max(tree[*i].nmax,tree[*i+].nmax);
} void update(int i,int s,int w){
if(tree[i].l==tree[i].r){
tree[i].nmax=w;
return;
} int mid=(tree[i].l + tree[i].r)/;
if(s<=mid) update(*i,s,w);
else update(*i+,s,w); tree[i].nmax=max(tree[*i].nmax,tree[*i+].nmax);
} void query(int i,int l,int r){//查询
if(tree[i].nmax<=nmax) return;
if(tree[i].l==l&&tree[i].r==r){
nmax = max(tree[i].nmax,nmax);
return;
}
int mid=(tree[i].l+tree[i].r)/;
if(r<=mid) query(*i,l,r);
else if(l>mid) query(*i+,l,r);
else{
query(*i,l,mid);
query(*i+,mid+,r);
}
} int main(){
while(scanf("%d %d",&n,&m)!=EOF){
memset(tree,,sizeof(tree));
for(int i=;i<=n;i++) scanf("%d",&a[i]); build_tree(,,n); while(m--){
scanf("%s",s);
if(s[]=='Q'){
int l,r;
scanf("%d %d",&l,&r); nmax=-INF;
query(,l,r); printf("%d\n",nmax);
}
if(s[]=='U'){
int u,v;
scanf("%d %d",&u,&v);
update(,u,v);
} } }
return ;
}

加油啊---gooooooooooooooooooooooo

HDU 1754 I Hate It【线段树 单点更新】的更多相关文章

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

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

  2. HDU 1754 I Hate It 线段树(单点更新,成段查询)

    题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=1754 题解: 单点更新,成段查询. 代码: #include<iostream> ...

  3. hdu 1754 I Hate It 线段树 单点更新 区间最值

    线段树功能:update:单点更新 query:区间最值 #include <bits/stdc++.h> #define lson l, m, rt<<1 #define r ...

  4. HDU 1754 I Hate It 线段树 单点更新 区间最大值

    #include<iostream> #include<string> #include<algorithm> #include<cstdlib> #i ...

  5. HDU.1166 敌兵布阵 (线段树 单点更新 区间查询)

    HDU.1166 敌兵布阵 (线段树 单点更新 区间查询) 题意分析 加深理解,重写一遍 代码总览 #include <bits/stdc++.h> #define nmax 100000 ...

  6. HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对)

    HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对) 题意分析 给出n个数的序列,a1,a2,a3--an,ai∈[0,n-1],求环序列中逆序对 ...

  7. HDU 1166 敌兵布阵(线段树单点更新,板子题)

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  8. HDU 1166 敌兵布阵(线段树单点更新)

    敌兵布阵 单点更新和区间更新还是有一些区别的,应该注意! [题目链接]敌兵布阵 [题目类型]线段树单点更新 &题意: 第一行一个整数T,表示有T组数据. 每组数据第一行一个正整数N(N< ...

  9. HDU 1166 敌兵布阵(线段树单点更新,区间查询)

    描述 C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况 ...

  10. HDU 1754 I Hate It(线段树单点替换+区间最值)

    I Hate It [题目链接]I Hate It [题目类型]线段树单点替换+区间最值 &题意: 本题目包含多组测试,请处理到文件结束. 在每个测试的第一行,有两个正整数 N 和 M ( 0 ...

随机推荐

  1. Unity 声音播放不受Time.scale为0的影响

    其他会暂停,目前发现声音不受影响 嗯,就这样.

  2. win10下CorelDRAW菜单栏字体变成白色了怎么办?

    相信很多同学安装了win10系统之后,你的 CDR 菜单栏就变了,变得没有任何内容,以白色显示,win10系统与CorelDRAW早期的版本兼容方面存在问题,(CorelDRAW x7/X8无此问题出 ...

  3. https://blog.csdn.net/sxf359/article/details/71082404

    https://blog.csdn.net/sxf359/article/details/71082404

  4. dp入门(先摆在这里,之后细细读)

    网址转载链接:  http://bbs.chinaunix.net/thread-4094539-1-1.html 动态规划:从新手到专家 Hawstein翻译 前言 我们遇到的问题中,有很大一部分可 ...

  5. 关于表格元素的使用,table、<width>、<heigh>、<border>、<tr>、<th>、<td>、<align>、<colspan>、<rowspan>

    <html>    <head>        <meta charset="UTF-8">        <title>个人简历& ...

  6. EM_LGH CF965D Single-use Stones 思维_推理

    Code: #include<cstdio> #include<algorithm> using namespace std; const int maxn = 1000000 ...

  7. 利用cookie判断文件下载完成

    在网页下载文件时,该文件又是通过后台代码生成的,比如报表之类的.当需要生成文件过大时会耗费很多时间,而文件生成好传到页面的时候也没有事件可以监听它,像微软官网,谷歌,百度等下载方式都是通过提示五秒过后 ...

  8. jq——css类

    1  addClass(classname) 添加类 <script type="text/javascript"> $("input").clic ...

  9. PAT 天梯赛练习集 L1-006. 连续因子

    题目链接:https://www.patest.cn/contests/gplt/L1-006 一个正整数N的因子中可能存在若干连续的数字.例如630可以分解为3*5*6*7,其中5.6.7就是3个连 ...

  10. 有效解决ajax传中文时,乱码的情况,php处理接收到的值

    在抽奖环节时,需把获奖名单通过ajax的post方式传输给php后台进行储存,但是php接收到的值确是乱码.在百度之后并没有找到合适的解决方法. 则使用js的encodeURI函数可以有效解决,但不知 ...