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> ...
随机推荐
- Solution for Error FRM-92095: Oracle Jnitiator version too low
Solution for Error FRM-92095: Oracle Jnitiator version too low By Pan.Tian on 六月 04, 2013 Symtom: Af ...
- 怎样获取Windows平台下SQL server性能计数器值
转载自工作伙伴Garrett, Helen "SQL Server Performance Counter captures" Capturing Windows Performa ...
- 关于访问链接返回XML的获取数据
1. 返回DataSet格式; /// <summary> /// 向某个url提交数据并读取该地址返回的xml,并将xml转换成dataset,并返回dataset中某个表 /// &l ...
- C#datagridview 防止闪烁的方法
描述:拉动DataGridView滚动条时会出现闪烁,看起来像是在重画,感觉不是很好. 解决方式:采用双缓存机制,在方案中添加方法. 代码: public static class Extension ...
- 以小时候玩的贪吃蛇为例,对于Java图像界面的学习感悟
简介 正文 01.JFrame是啥? 02.JPanel 03. KeyListener 04.Runnable 05.游戏Running 06.游戏初始类编写 07.main 简介: 一直以来用代码 ...
- zigbee学习之路(十一):看门狗
一.前言 今天,我们要通过实验学习和认识一下看门狗的使用,看门狗是为了防止防止程序跑飞的,通过不断的喂狗,使看门狗能持续监管程序的运行状态,当程序跑飞时,能及时把程序拽回来. 二.原理与分析 在CPU ...
- Android first --- 页面跳转及数据传递
页面跳转即数据传递 创建第二个界面Acivity *需要在清单文件中添加配置一个Actuvity标签 标签中如果带有这个子节点,则会在Android中添加一个快捷图标 <intent-filte ...
- String 字符串递归截取字节字符串
public static String idgui(String s,int num)throws Exception{ int changdu = s.getBytes("UTF-8&q ...
- 对teacher表进行增加,删除,修改
<%@page import="java.text.SimpleDateFormat"%> <%@ page language="java" ...
- 使用Json出现java.lang.NoClassDefFoundError解决方法
前几天在项目使用到Json格式数据,于是把使用Json需要用到的包都引到了工程里面,程序写好后运行时,发现后台报 java.lang.NoClassDefFoundError: net/sf/json ...