》》点击进入原题测试《《

思路:线段树水题,可以手敲

#include<string>
#include<iostream>
#include<algorithm> #define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1 using namespace std; const int maxn = 2e5 + ; int tree[maxn << ]; void build(int l, int r, int rt)
{
if (l == r){
cin >> tree[rt];
return;
}
int m = (l + r) >> ;
build(lson);
build(rson);
tree[rt] = max(tree[rt << ], tree[rt << | ]);
}
void update(int x, int ans, int l, int r, int rt)
{
if (l == r){
tree[rt] = ans;
return;
}
int m = (l + r) >> ;
if (x <= m)update(x, ans, lson);
else update(x, ans, rson);
tree[rt] = max(tree[rt << ] , tree[rt << | ]);
}
int query(int L, int R, int l, int r, int rt)
{
if (L <= l&&r <= R){
return tree[rt];
}
int m = (l + r) >> , ans = ;
if (L <= m)ans = max(ans, query(L, R, lson));
if (R > m)ans = max(ans, query(L, R, rson));
return ans;
}
void Print(int l, int r, int rt)
{
if (l == r){
cout << rt << " = " << tree[rt] << endl;
return;
}
cout << rt << " = " << tree[rt] << endl;
int m = (l + r) >> ;
if (l <= m)Print(lson);
if (r > m)Print(rson);
}
int main()
{
std::ios::sync_with_stdio(false); int n, q;
while (cin >> n >> q){
build(, n, );
string flag; int i, j;
while (q--){
cin >> flag >> i >> j;
if (flag == "U"){
update(i, j, , n, );
// Print(1, n, 1);
}
else if (flag == "Q"){
cout << query(i, j, , n, ) << endl;
}
} } return ;
}

hdu 1754 I Hate It(线段树水题)的更多相关文章

  1. hdu 1754 I Hate It 线段树基础题

    Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求, ...

  2. hdu - 1394 Minimum Inversion Number(线段树水题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1394 很基础的线段树. 先查询在更新,如果后面的数比前面的数小肯定会查询到前面已经更新过的值,这时候返回的sum ...

  3. HDU 1754 I Hate It(线段树模板题)

    题目链接: 传送门 I Hate It Time Limit: 3000MS     Memory Limit: 32768 K Description 很多学校流行一种比较的习惯.老师们很喜欢询问, ...

  4. hdu 1754 I Hate It 线段树 点改动

    // hdu 1754 I Hate It 线段树 点改动 // // 不多说,裸的点改动 // // 继续练 #include <algorithm> #include <bits ...

  5. POJ 3468 A Simple Problem with Integers(线段树水题)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 135904 ...

  6. HDU 1754 I Hate It 线段树单点更新求最大值

    题目链接 线段树入门题,线段树单点更新求最大值问题. #include <iostream> #include <cstdio> #include <cmath> ...

  7. HDU 1754 I Hate It(线段树之单点更新,区间最值)

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  8. HDU 1754 I Hate It 线段树RMQ

    I Hate It Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=175 ...

  9. HDU 1754 I Hate It(线段树单点替换+区间最值)

    I Hate It [题目链接]I Hate It [题目类型]线段树单点替换+区间最值 &题意: 本题目包含多组测试,请处理到文件结束. 在每个测试的第一行,有两个正整数 N 和 M ( 0 ...

随机推荐

  1. easyui图标对照

    转自:https://blog.csdn.net/qq_34545192/article/details/78250816 原作者文章地址: http://www.cnblogs.com/timeme ...

  2. SQL Server 添加描述

    添加描述的格式 exec sys.sp_addextendedproperty @name = N'MS_Description' ,@value = 'value',@level0type=N'SC ...

  3. 清北考前刷题day7早安

  4. ionic安卓打包apk--安卓签名

    上周项目上线,在网上看了看打包的博客,感觉不是很清晰我自己来总结下 首先,我们在项目的根目录下 build android apk 的时候执行的命令一定要是 ionic build android - ...

  5. extjs grid禁止表格头部使用鼠标拖拽改变宽度

    extjs6 经典版 表格头部使用鼠标拖动 禁止改变列的宽度 只需要给grid 设置属性enableColumnResize:false就可以啦 xtype:'grid', enableColumnR ...

  6. 贪心 HDOJ 5355 Cake

    好的,数据加强了,wa了 题目传送门 /* 题意:1到n分成m组,每组和相等 贪心:先判断明显不符合的情况,否则肯定有解(可能数据弱?).贪心的思路是按照当前的最大值来取 如果最大值大于所需要的数字, ...

  7. BFS POJ 3414 Pots

    题目传送门 /* BFS:六种情况讨论一下,BFS轻松解决 起初我看有人用DFS,我写了一遍,TLE..还是用BFS,结果特判时出错,逗了好长时间 看别人的代码简直是受罪,还好自己终于发现自己代码的小 ...

  8. 贪心 Codeforces Round #135 (Div. 2) C. Color Stripe

    题目传送门 /* 贪心:当m == 2时,结果肯定是ABABAB或BABABA,取最小改变量:当m > 2时,当与前一个相等时, 改变一个字母 同时不和下一个相等就是最优的解法 */ #incl ...

  9. ACM_递推题目系列之二认错人(递推dp)

    递推题目系列之二认错人 Time Limit: 2000/1000ms (Java/Others) Problem Description: 国庆期间,省城HZ刚刚举行了一场盛大的集体婚礼,为了使婚礼 ...

  10. Node“getTextContent() is undefined for the type Node”处理办法

    最近一个项目在MyEclipse导入后总是报getTextContent() is undefined for the type Node错误. 经过查找原来是因为Node类为JDK中自带的(org. ...