【题目链接】

点击打开链接

【算法】

树状数组的最值查询

详见这篇文章 : 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. 《Java虚拟机原理图解》 1.2、class文件中的常量池

    了解JVM虚拟机原理 是每一个Java程序员修炼的必经之路.但是由于JVM虚拟机中有很多的东西讲述的比较宽泛,在当前接触到的关于JVM虚拟机原理的教程或者博客中,绝大部分都是充斥的文字性的描述,很难给 ...

  2. 利用systemtap定位ifconfig dropped数据包的原因

    http://blog.chinaunix.net/uid-20662820-id-3842431.html   欢迎转载,转载请保留文章的完整性!Author: Tony <tingw.liu ...

  3. MongoDB---出现no write has been done on this connection解决方式

    no write has been done on this connection 这个问题出现了好几天.日志里面一天出现几十次no write has been done on this conne ...

  4. C++简单实现对象引用计数示例(转)

    C++简单实现对象引用计数示例 #include <iostream> #include <stdio.h> using namespace std; class String ...

  5. [LeetCode][Java] Longest Common Prefix

    题目: Write a function to find the longest common prefix string amongst an array of strings. 题意: 写出一个函 ...

  6. Oracle创建索引的原则(转)

    Oracle 建立索引及SQL优化 数据库索引: 索引有单列索引复合索引之说 如何某表的某个字段有主键约束和唯一性约束,则Oracle 则会自动在相应的约束列上建议唯一索引.数据库索引主要进行提高访问 ...

  7. China Vis 2015 会议小结

    China Vis 2015  Paper有6个分会场.主要有 1.天气.气象.灾害可视化. 2.文本可视化应用: 3.树.网络.以及高维技术. 4.时空分析. 5.科学可视化与应用: 五个方面主题. ...

  8. opencvSGBM半全局立体匹配算法的研究(1)

    转载请说明出处:http://blog.csdn.net/zhubaohua_bupt/article/details/51866567 这段时间对opencvSGBM半全局立体匹配算法进行了比較仔细 ...

  9. actionbar tab 字体大小设置

    在styles.xml文件里加入以下的样式就可以 <!-- Application theme. -->     <style name="AppTheme" p ...

  10. chrome自带的调试工具

    由于项目需要加载webgl对浏览器内存压力很大,需要优化内存,网上找了一下资料,极力推荐chrome的开发文档 https://developers.google.cn/web/tools/chrom ...