【题目链接】

点击打开链接

【算法】

树状数组的最值查询

详见这篇文章 : https://blog.csdn.net/u010598215/article/details/48206959

【代码】

#include<bits/stdc++.h>
using namespace std;
#define MAXN 200000 int i,N,M,x,y,b;
int a[MAXN+];
char opt; template <typename T> inline void read(T &x) {
int f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) { if (c == '-') f = -f; }
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
} template <typename T> inline void write(T x) {
if (x < ) { putchar('-'); x = -x; }
if (x > ) write(x/);
putchar(x%+'');
} template <typename T> inline void writeln(T x) {
write(x);
puts("");
} struct BinaryIndexedTree {
int bit[MAXN+];
inline int lowbit(int x) { return x & -x; }
inline void clear() {
int i;
for (i = ; i <= N; i++) bit[i] = ;
}
inline void modify(int pos,int val) {
int i,j,t;
for (i = pos; i <= N; i += lowbit(i)) {
bit[i] = a[i];
t = lowbit(i);
for (j = ; j < t; j <<= ) bit[i] = max(bit[i],bit[i-j]);
}
}
inline int query(int l,int r) {
int ret = ;
while (r >= l) {
if (r - lowbit(r) < l) {
ret = max(ret,a[r]);
r--;
continue;
}
while (r - lowbit(r) >= l) {
ret = max(ret,bit[r]);
r -= lowbit(r);
}
}
return ret;
}
} BIT; int main() { while (scanf("%d%d",&N,&M) != EOF) {
BIT.clear();
for (i = ; i <= N; i++) {
read(a[i]);
BIT.modify(i,a[i]);
}
while (M--) {
opt = getchar();
if (opt == 'U') {
read(x); read(b);
a[x] = b;
BIT.modify(x,b);
} else {
read(x); read(y);
writeln(BIT.query(x,y));
}
}
} return ;
}

【HDU 1754】 I Hate It的更多相关文章

  1. 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题

    [HDU  3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...

  2. 【HDU 5647】DZY Loves Connecting(树DP)

    pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...

  3. -【线性基】【BZOJ 2460】【BZOJ 2115】【HDU 3949】

    [把三道我做过的线性基题目放在一起总结一下,代码都挺简单,主要就是贪心思想和异或的高斯消元] [然后把网上的讲解归纳一下] 1.线性基: 若干数的线性基是一组数a1,a2,a3...an,其中ax的最 ...

  4. 【HDU 2196】 Computer(树的直径)

    [HDU 2196] Computer(树的直径) 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 这题可以用树形DP解决,自然也可以用最直观的方法解 ...

  5. 【HDU 2196】 Computer (树形DP)

    [HDU 2196] Computer 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 刘汝佳<算法竞赛入门经典>P282页留下了这个问题 ...

  6. 【HDU 5145】 NPY and girls(组合+莫队)

    pid=5145">[HDU 5145] NPY and girls(组合+莫队) NPY and girls Time Limit: 8000/4000 MS (Java/Other ...

  7. 【hdu 1043】Eight

    [题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=1043 [题意] 会给你很多组数据; 让你输出这组数据到目标状态的具体步骤; [题解] 从12345 ...

  8. 【HDU 3068】 最长回文

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3068 [算法] Manacher算法求最长回文子串 [代码] #include<bits/s ...

  9. 【HDU 4699】 Editor

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=4699 [算法] 维护两个栈,一个栈放光标之前的数,另外一个放光标之后的数 在维护栈的同时求最大前缀 ...

随机推荐

  1. js react 全选和反选

    onCheckAll = (data) => { var CheckBox = document.getElementsByName(data); for(let i=0;i<CheckB ...

  2. cssnext下一代的css

    前端技术更新迭代的速度令人咂舌,互联网+的风头刚起那几年,前端技术大多还停留在jquery阶段,按需加载还停留在seajs和requirejs的阶段,css3和H5也不过才崭露头角,但经过几年的飞速发 ...

  3. 常用业务返回对象类ResponseJson

    目录 1.ResponseJson类 2.使用举例 1.ResponseJson类 import java.io.Serializable; public class ResponseJson imp ...

  4. Spring的依赖注入概述

    以下内容引用自http://wiki.jikexueyuan.com/project/spring/dependency-injection.html: 每个基于Java应用程序都有几个对象,这些对象 ...

  5. 学习日记之抽象工厂模式和Effective C++

    抽象工厂模式(Abstract Factory):提供一个创建一系列相关或者相互依赖对象的接口.而无需制定他们详细的类. (1),工厂方法模式是定义一个用于创建对象的接口.让子类决定实例化哪一个类. ...

  6. 取汉子拼音首字母的C#方法

    /// <summary> /// 获得一个字符串的汉语拼音码 /// </summary> /// <param name="strText"> ...

  7. centos 7 卸載 mysql

    跟網上文章,安裝了一個mysqlwget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm 記下卸載過程: 首先执行查看命令 ...

  8. AnimalWindow使用,实现界面动态消失

    http://m.blog.csdn.net/blog/shufac/24932279 http://blog.sina.com.cn/s/blog_455245fc01000a42.html Ani ...

  9. 浅谈MySQL压缩协议细节--从源码层面

    压缩协议属于mysql通讯协议的一部分,要启用压缩协议传输功能,前提条件客户端和服务端都必须要支持zlib算法,那么,现在有个问题,假如服务端已经默认开启压缩功能,那原生客户端在连接的时候要如何才可启 ...

  10. HTML URL编码规则

    将空格转换为加号(+) 对0-9,a-z,A-Z之间的字符保持不变 对于所有其他的字符,用这个字符的当前字符集编码在内存中的十六进制格式表示,并在每个字节前加上一个百分号(%).如字符“+”用%2B表 ...