hdu 1754 I Hate It(线段树水题)


思路:线段树水题,可以手敲
#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(线段树水题)的更多相关文章
- hdu 1754 I Hate It 线段树基础题
Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求, ...
- hdu - 1394 Minimum Inversion Number(线段树水题)
http://acm.hdu.edu.cn/showproblem.php?pid=1394 很基础的线段树. 先查询在更新,如果后面的数比前面的数小肯定会查询到前面已经更新过的值,这时候返回的sum ...
- HDU 1754 I Hate It(线段树模板题)
题目链接: 传送门 I Hate It Time Limit: 3000MS Memory Limit: 32768 K Description 很多学校流行一种比较的习惯.老师们很喜欢询问, ...
- hdu 1754 I Hate It 线段树 点改动
// hdu 1754 I Hate It 线段树 点改动 // // 不多说,裸的点改动 // // 继续练 #include <algorithm> #include <bits ...
- POJ 3468 A Simple Problem with Integers(线段树水题)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 135904 ...
- HDU 1754 I Hate It 线段树单点更新求最大值
题目链接 线段树入门题,线段树单点更新求最大值问题. #include <iostream> #include <cstdio> #include <cmath> ...
- HDU 1754 I Hate It(线段树之单点更新,区间最值)
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 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 ...
- HDU 1754 I Hate It(线段树单点替换+区间最值)
I Hate It [题目链接]I Hate It [题目类型]线段树单点替换+区间最值 &题意: 本题目包含多组测试,请处理到文件结束. 在每个测试的第一行,有两个正整数 N 和 M ( 0 ...
随机推荐
- IDEA中项目src目录下无法创建java文件的问题
出现的问题如下,是因为该目录不是源码目录 解决办法 设置成功
- hdu1213 并查集不压缩
题意:题意:一个人请人吃饭,相互认识的朋友在一张桌子,相互认识的朋友的意思是如果A认识B,B认识C,那么A.B.C是朋友,对于每组输入输出桌子的张数. Sample Input 2 5 3 1 2 2 ...
- Windows 和 Linux 上Redis的安装守护进程配置
# Windows 和 Linux 上Redis的安装守护进程配置 Redis 简介 Redis是目前最常用的非关系型数据库(NOSql)之一,常以Key-Value的形式存储.Redis读写速度 ...
- 例题 5-1 STL
Raju and Meena love to play with Marbles. They have got a lot of marbles with numbers written on the ...
- 数据结构之顺序队列(C实现)
一.队列是什么 队列是一种可以实现“先进先出”的存储结构. 队列通常可以分为两种类型: 一.顺序队列,采用顺序存储,当长度确定时使用. 顺序队列又有两种情况: ①使用数组存储队列的称为静态顺序队列. ...
- Poj 3694 Network (连通图缩点+LCA+并查集)
题目链接: Poj 3694 Network 题目描述: 给出一个无向连通图,加入一系列边指定的后,问还剩下多少个桥? 解题思路: 先求出图的双连通分支,然后缩点重新建图,加入一个指定的边后,求出这条 ...
- 数据传递-------@ResponseBody
1.导入jar包 jack-core-asl-1.9.11.jar jack-mapper-asl-1.9.11.jar 2.配置springmvc-servlet.xml文件 <?xml ve ...
- asp.net ajax get post 中文乱码解决办法
前台: var username = $("#UserName").val(); var tel = $("#tel").val(); var yzm = $( ...
- SVN服务器搭建 内网可用外网不可用的问题
检查1:内网端口映射到了外网端口,这样外网才能够访问到 映射的方式有两种: 1.通过路由器的虚拟服务器功能,网上一搜一大把. 2.将路由器的DMZ功能开启,并把DMZ主机设置为目标计算机. 检查2:S ...
- 添加telnet命令
打开控制面板,打开程序和功能,看到左边有个“打开或关闭Windows功能 ,打开找到telnet客户端,把这2项都勾选上,然后确定就可以了 注意,如果只要telnet别人的话,就选telnet客户端. ...