HDU 1754.I Hate It-完全版线段树(单点替换、区间最值)
HDU1754.I Hate It
直接模板就可以了
代码:
//B
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const double eps=1e-;
const int maxn=*1e5+;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
int sum[maxn<<],MAX[maxn<<]; void PushUp(int rt){
//sum[rt]=sum[rt<<1]+sum[rt<<1|1];
MAX[rt]=max(MAX[rt<<],MAX[rt<<|]);
} void build(int l,int r,int rt){
if(l==r){
//scanf("%d",&sum[rt]);
scanf("%d",&MAX[rt]);
return ;
}
int m=(l+r)>>;
build(lson);
build(rson);
PushUp(rt);
}
/*
//单点增减
void update(int p,int add,int l,int r,int rt){
if(l==r){
sum[rt]+=add;
return ;
}
int m=(l+r)>>1;
if(p<=m)update(p,add,lson);
else update(p,add,rson);
PushUp(rt);
}
*/ //单点更新
void update(int p,int sc,int l,int r,int rt){
if(l==r){
MAX[rt]=sc;
return ;
}
int m=(l+r)>>;
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){
if(L<=l&&r<=R){
return sum[rt];
}
int m=(l+r)>>1;
int ret=0;
if(L<=m)ret+=query(L,R,lson);
if(R>m) ret+=query(L,R,rson);
return ret;
}
*/ //区间最值
int query(int L,int R,int l,int r,int rt){
if(L<=l&&r<=R){
return MAX[rt];
}
int m=(l+r)>>;
int ret=;
if(L<=m)ret=max(ret,query(L,R,lson));
if(R>m) ret=max(ret,query(L,R,rson));
return ret;
} int main(){
int n,m;
while(~scanf("%d%d",&n,&m)){
build(,n,);
char s[];int a,b;
while(m--){
scanf("%s%d%d",s,&a,&b);
if(s[]=='Q')printf("%d\n",query(a,b,,n,));
else update(a,b,,n,);
}
}
return ;
}
HDU 1754.I Hate It-完全版线段树(单点替换、区间最值)的更多相关文章
- HDU 1754 I Hate It(线段树单点替换+区间最值)
I Hate It [题目链接]I Hate It [题目类型]线段树单点替换+区间最值 &题意: 本题目包含多组测试,请处理到文件结束. 在每个测试的第一行,有两个正整数 N 和 M ( 0 ...
- hdu1754(线段树单点替换&区间最值模板)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754 题意:中文题诶- 思路:线段树单点替换&区间最大值查询模板 代码: #include & ...
- hihoCoder #1586 : Minimum-结构体版线段树(单点更新+区间最值求区间两数最小乘积) (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
#1586 : Minimum Time Limit:1000ms Case Time Limit:1000ms Memory Limit:256MB Description You are give ...
- HDU 1166.敌兵布阵-完全版线段树(单点增减、区间求和)
生活艰辛,且行且珍惜. 先水一篇博客再去补题,要不然又忘记写博客了. 计划系统的刷一遍线段树专题,自己给自己找虐(自作孽不可活),从基础的到后面的,所有的都挂了题,刷题不,大兄弟? 线段树可真有意思, ...
- hdu2795(线段树单点更新&区间最值)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 题意:有一个 h * w 的板子,要在上面贴 n 条 1 * x 的广告,在贴第 i 条广告时要 ...
- 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 ——线段树 单点更新 区间最值
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- hdu 1754 I Hate It 线段树 单点更新 区间最值
线段树功能:update:单点更新 query:区间最值 #include <bits/stdc++.h> #define lson l, m, rt<<1 #define r ...
- HDU 1754 I Hate It(线段树单点更新区间最值查询)
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
随机推荐
- centos使用--ssh登陆
1 安装openssh-server yum install openssh-server 2 登录 在配置好ssh后就可以只使用SSH密钥登录而不允许通过密码登录了,方法如下: 修改ssh配置: v ...
- 【Balanced Binary Tree】cpp
题目: Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced bin ...
- Python学习-前台开发-ajax操作
概述 对于WEB应用程序:用户浏览器发送请求,服务器接收并处理请求,然后返回结果,往往返回就是字符串(HTML),浏览器将字符串(HTML)渲染并显示浏览器上. 1.传统的Web应用 一个简单操作需要 ...
- 【志银】Win764位配置Github环境及将代码部署到Github pages-志银强势总结
(软件及教程下载分享:链接:http://pan.baidu.com/s/1dFysay9 密码:pug0) 1-安装Git-2.9.2-64-bit.exe(解压安装文件,运行安装程序,除了记得修改 ...
- hnust 神奇的序列
问题 E: 神奇的序列 时间限制: 1 Sec 内存限制: 128 MB提交: 635 解决: 84[提交][状态][讨论版] 题目描述 Aurora在南宁发现了一个神奇的序列,即对 ...
- 团队项目-第一次Scrum 会议
时间:10.23 时长:30分钟 地点:F楼2层沙发休息处 工作情况 团队成员 已完成任务 待完成任务 解小锐 学习使用cocos creator 学习官方样例 陈鑫 学习JavaScript 学习c ...
- 基于MAC OS 操作系统安装、配置hadoop
在Mac上安装Hadoop 对我这个之前从未接触过*nix的用户来说,使用命令行来做一系列的事情还是废了一番功夫.特写这个记录,以做备份. 获取Java 我的Mac运行的操作系统是OS X 10.7 ...
- 【bzoj1927】[Sdoi2010]星际竞速 有上下界费用流
原文地址:http://www.cnblogs.com/GXZlegend/p/6832464.html 题目描述 10年一度的银河系赛车大赛又要开始了.作为全银河最盛大的活动之一,夺得这个项目的冠军 ...
- [TJOI2017][bzoj4889] 不勤劳的图书管理员 [线段树套线段树]
题面 传送门 思路 考虑两本书的位置交换对答案的贡献: (为了方便描述,用"左边那本"和"右边那本"称呼两本我们要交换的书,"中间那本"是我 ...
- [bzoj] 3224 Tyvj 1728 普通平衡树 || 平衡树板子题
#include<cstdio> #define N 100010 #define which(x) (ls[f[(x)]]==(x)) using namespace std; int ...