【HDU 1754】 I Hate It
【题目链接】
【算法】
树状数组的最值查询
详见这篇文章 : 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的更多相关文章
- 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题
[HDU 3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...
- 【HDU 5647】DZY Loves Connecting(树DP)
pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...
- -【线性基】【BZOJ 2460】【BZOJ 2115】【HDU 3949】
[把三道我做过的线性基题目放在一起总结一下,代码都挺简单,主要就是贪心思想和异或的高斯消元] [然后把网上的讲解归纳一下] 1.线性基: 若干数的线性基是一组数a1,a2,a3...an,其中ax的最 ...
- 【HDU 2196】 Computer(树的直径)
[HDU 2196] Computer(树的直径) 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 这题可以用树形DP解决,自然也可以用最直观的方法解 ...
- 【HDU 2196】 Computer (树形DP)
[HDU 2196] Computer 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 刘汝佳<算法竞赛入门经典>P282页留下了这个问题 ...
- 【HDU 5145】 NPY and girls(组合+莫队)
pid=5145">[HDU 5145] NPY and girls(组合+莫队) NPY and girls Time Limit: 8000/4000 MS (Java/Other ...
- 【hdu 1043】Eight
[题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=1043 [题意] 会给你很多组数据; 让你输出这组数据到目标状态的具体步骤; [题解] 从12345 ...
- 【HDU 3068】 最长回文
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3068 [算法] Manacher算法求最长回文子串 [代码] #include<bits/s ...
- 【HDU 4699】 Editor
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=4699 [算法] 维护两个栈,一个栈放光标之前的数,另外一个放光标之后的数 在维护栈的同时求最大前缀 ...
随机推荐
- 关于MySQL存储过程异常处理的一点心得
DROP PROCEDURE IF EXISTS `SP_MODEL`; DELIMITER ;;CREATE PROCEDURE `SP_MODEL`(IN V_TYPE INT)BEGIN /** ...
- codevs3249搭积木
3249 搭积木 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description Petya有一个A×B×C的长方体积木,积 ...
- Codeforces 961 D Pair Of Lines
题目描述 You are given nn points on Cartesian plane. Every point is a lattice point (i. e. both of its c ...
- kafka基础介绍
kafka基础介绍 一.kafka介绍 1.1主要功能 根据官网的介绍,kafka是一个分布式流媒体的平台,它主要有三大功能: 1.11:It lets you publish and subscri ...
- How to Install a Language Pack
https://www.phpbb.com/kb/article/how-to-install-a-language-pack
- 【内核研究】处理者_Handler
虽然MessageQueue提供了直接读/写的函数接口.但对于程序猿来说,一般不直接读/写消息队列.之前了解到,在Looper.loop()函数中.当取出消息后,会回调msg.target对象的han ...
- jquery提示消息,简单通用
jquery提示消息.简单通用 function showTips(txt,time,status) { var htmlCon = ''; if(txt != ''){ if(status != 0 ...
- 重装系统(Win)
有朋友问我,重装系统该怎样操作呢? 1. 硬盘重装 官网:http://www.heiyunwang.com/ ,点击下载软件:http://dlsw.baidu.com/sw-search-sp/s ...
- unity常见问题之20题
1:天空盒有接缝怎么解决? 答:在贴图导入设置里设置Wrap Mode为"Clamp". 2: DDS格式怎么不显示? 答:Unity不支持DDS格式,Unity会将除DDS外的其 ...
- Hibernate - DetachedCriteria 的完整用法(转)
现在对 Hibernate的Criteria 的用法进行总结: Hibernate 设计了 CriteriaSpecification 作为 Criteria 的父接口,下面提供了 Crite ...