hdu1754 I Hate It
题目链接:hdu1754 I Hate It
树状数组学习参考博客:http://blog.csdn.net/u010598215/article/details/48206959
树状数组之前没看懂就放着一直没看了,现在抽空学下...
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#define CLR(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long ll;
const int N = ;
int n;
int a[N];
int tree[N];
int lowbit(int x){
return x&(-x);
}
void update(int pos){
int lx, i;
while(pos <= n){
tree[pos] = a[pos];
lx = lowbit(pos);
for(i = ; i < lx; i <<= )
tree[pos] = max(tree[pos], tree[pos-i]);
pos += lowbit(i);
}
}
int query_ma(int x, int y){
int ma = ;
while(y >= x){
ma = max(ma, a[y]);
y--;
for(; y - lowbit(y) >= x; y -= lowbit(y))
ma = max(tree[y], ma);
}
return ma;
}
int main(){
int m, i;
while(~scanf("%d%d", &n, &m)){
CLR(tree, );
for(i = ; i <= n; ++i){
scanf("%d", &a[i]);
update(i);
}
int l, r;
char c;
while(m--){
scanf("%*c%c%d%d", &c, &l, &r);
if(c == 'Q')
printf("%d\n", query_ma(l,r));
else {
a[l] = r;
update(l);
}
}
}
return ;
}
hdu1754 I Hate It的更多相关文章
- I Hate It(hdu1754)(线段树区间最大值)
I Hate It hdu1754 Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- [线段树]HDU-1754板子题入门ver
HDU-1754 线段树数组请开到四倍 众所周知数组开小会导致re tle wa等一系列问题orz 板子就是板子,数组从零开始或是从一开始都没什么问题,就是2*root+1还是2*root+2的问题. ...
- HDU1754 —— I Hate It 线段树 单点修改及区间最大值
题目链接:https://vjudge.net/problem/HDU-1754 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感. 不管你喜不喜 ...
- HDU1754 && HDU1166 线段树模板题
HDU1754 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754 题目分析:对于给出的一个很长的区间,对其进行单点更新值和区间求最大值的操作,由于 ...
- HDU1166(线段树 +更新单点,求区间总和)、HDU1754(线段树 + 更新单点,求区间最大值)
线段树简单应用 先附上几张图便与理解,大佬文章传送门1.传送门2 HDU1166:题目描述 线段树 +更新单点,求区间总和 代码如下(递归版) #include<iostream> #in ...
- hdu1754 I hate it线段树模板 区间最值查询
题目链接:这道题是线段树,树状数组最基础的问题 两种分类方式:按照更新对象和查询对象 单点更新,区间查询; 区间更新,单点查询; 按照整体维护的对象: 维护前缀和; 维护区间最值. 线段树模板代码 # ...
- hdu1754 线段树
Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少.这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写 ...
- hdu1754线段树维护区间最大值
#include <iostream> #include <cstdio> using namespace std; #define MAXN 200005 int N,M; ...
- 线段树---HDU1754 I hate it
这个题也是线段树的基础题,有了上一个题的基础,在做这个题就显得比较轻松了,大体都是一样的,那个是求和,这个改成求最大值,基本上思路差不多,下面是代码的实现 #include <cstdio> ...
随机推荐
- css样式控制 字符个数,多余的字用省略号代替
大家好,我是小菜 前端 ,技术不高,正在努力中充电!希望大家多多指教 <div class="show">大家好,我是小菜 前端 ,技术不高,正在努力中充电!希望大家多 ...
- linux常用的命令
Linux简介及Ubuntu安装 Linux,免费开源,多用户多任务系统.基于Linux有多个版本的衍生.RedHat.Ubuntu.Debian 安装VMware或VirtualBox虚拟机.具体安 ...
- 采用重写tostring方法使ComboBox显示对象属性
当ComboBox中添加的是对象集合的时候,如果运行就会发现显示是的命令空间.类名,而如果我们想显示对象属性名的时候,我们就可以在对象类中重写object基类中的tostring方法.
- 山东省第七届ACM省赛------Triple Nim
Triple Nim Time Limit: 2000MS Memory limit: 65536K 题目描述 Alice and Bob are always playing all kinds o ...
- Linux之RHEL6的开机流程分析
开机——很多人觉得很简单的事情,只要按下电源开关,然后系统就会自然启动,没有什么需要学习的.其实不然,如果系统没有什么问题,可以正常登陆的时候,当然开机很简单.但更多的时候,我们需要知道当机子不能正常 ...
- centos升级glibc(升级到2.14版)
1.下载源码包 到http://ftp.gnu.org/gnu/glibc/下载glibc-2.14.tar.xz 2.解压 tar glibc-2.14.tar.gz 3.创建build目录 cd ...
- ElasticSearch与Spring Boot集成问题
1.None of the configured nodes are available 或者 org.elasticsearch.transport.RemoteTransportException ...
- SQL函数
1,字符串截取拼接 CONCAT(),'****');SUBSTRING_INDEX(c.context,'}',1);SUBSTRING_INDEX(a.task_context,':',-1) a ...
- LeetCode——Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- JavaScript中的各种宽高属性
转自慕课网:http://www.imooc.com/article/14516 在js中,存在着N多的关于高度和宽度的属性,比如:clientHeight.offsetHeight.scroll ...