kuangbin_SegTree B (HDU 1754)
跟A题类似 只是把update从增减直接改为赋值 query从求和改为求最大值 其他几乎一样
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#define INF 0x3f3f3f3f
#define lson l, m, root<<1
#define rson m+1, r, root<<1|1
using namespace std; const int MAXN = 2e5+;
int val[MAXN*]; void pushup(int root)
{
val[root] = max(val[root<<], val[root<<|]);
} void build(int l, int r, int root)
{
if(l == r) scanf("%d", &val[root]);
else{
int m = (l + r) >> ;
build(lson);
build(rson);
pushup(root);
}
} void update(int point, int value, int l, int r, int root)
{
if(l == r) val[root] = value;
else{
int m = (l + r) >> ;
if(point <= m) update(point, value, lson);
else update(point, value, rson);
pushup(root);
}
} int query(int L, int R, int l, int r, int root)
{
if(L <= l && R >= r) return val[root];
int res = ;
int m = (l + r) >> ;
if(L <= m) res = max(res, query(L, R, lson));
if(R > m) res = max(res, query(L, R, rson));
return res;
} int main()
{
int n, m;
while(~scanf("%d%d", &n, &m)){
build(, n, );
char op[];
while(m--){
scanf("%s", op);
int u, v;
scanf("%d%d", &u, &v);
if(op[] == 'U') update(u, v, , n, );
else{
if(u > v) swap(u, v);
printf("%d\n", query(u, v, , n, ));
}
}
}
return ;
}
kuangbin_SegTree B (HDU 1754)的更多相关文章
- hdu 1754 Ihate it
I Hate It Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit St ...
- hdu 1754 I Hate It (splay tree伸展树)
hdu 1754 I Hate It 其实我只是来存一下我的splay模板的..请大牛们多多指教 #include<stdio.h> #include<string.h> #i ...
- hdu 1754 线段树(Max+单点修改)
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- hdu 1754 I Hate It (线段树功能:单点更新和区间最值)
版权声明:本文为博主原创文章.未经博主同意不得转载.vasttian https://blog.csdn.net/u012860063/article/details/32982923 转载请注明出处 ...
- HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值)
HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值) 点我挑战题目 题意分析 从题目中可以看出是大数据的输入,和大量询问.基本操作有: 1.Q(i,j)代表求区间max(a ...
- HDU 1754——I Hate It——————【线段树单点替换、区间求最大值】
I Hate It Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit St ...
- 线段树(单点更新) HDU 1754 I Hate It
题目传送门 /* 线段树基本功能:区间最大值,修改某个值 */ #include <cstdio> #include <cstring> #include <algori ...
- hdu 1754 I Hate It 线段树 点改动
// hdu 1754 I Hate It 线段树 点改动 // // 不多说,裸的点改动 // // 继续练 #include <algorithm> #include <bits ...
- hdu 1754 I Hate It (模板线段树)
http://acm.hdu.edu.cn/showproblem.php?pid=1754 I Hate It Time Limit: 9000/3000 MS (Java/Others) M ...
随机推荐
- php总结 --- 4. 对象
一. 恩聪 设计模式 因为php本身的问题,所以他能做的模式有限,就在这边列出了
- First Day
以后这里将记录我的成长脚步啦~~ 欢迎吐槽 作为一个大三即将面临找工作的学渣,心中真的很焦急 要好好学前端!! Fighting~
- USACO2007Monthly Expense月度开销
Description Farmer John是一个令人惊讶的会计学天才,他已经明白了他可能会花光他的钱,这些钱本来是要维持农场每个月的正常运转的.他已经计算了他以后N(1<=N<=100 ...
- Centos6下rpm安装MySQL5.6
Centos6在rpm安装 rpm -ivh http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm yum install ...
- ruby bundle config 镜像映射配置
新增映射 : bundle config mirror.https://rubygems.org/ http://ruby.taobao.com #所有对source https://rubygems ...
- Construct Binary Tree from Preorder and Inorder Traversal [LeetCode]
Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...
- BZOJ2480 Spoj3105 Mod
乍一看题面:$$a^x \equiv b \ (mod \ m)$$ 是一道BSGS,但是很可惜$m$不是质数,而且$(m, a) \not= 1$,这个叫扩展BSGS[额...... 于是我们需要通 ...
- Java 并发和多线程(一) Java并发性和多线程介绍[转]
作者:Jakob Jenkov 译者:Simon-SZ 校对:方腾飞 http://tutorials.jenkov.com/java-concurrency/index.html 在过去单CPU时 ...
- iOS开发UI篇—Quartz2D简单使用(二)
iOS开发UI篇—Quartz2D简单使用(二) 一.画文字 代码: // // YYtextview.m // 04-写文字 // // Created by 孔医己 on 14-6-10. // ...
- iOS开发拓展篇—CoreLocation地理编码
iOS开发拓展篇—CoreLocation地理编码 一.简单说明 CLGeocoder:地理编码器,其中Geo是地理的英文单词Geography的简写. 1.使用CLGeocoder可以完成“地理编码 ...