【HDU1754】I Hate It(线段树)
update:单点替换 query:区间最值
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <numeric>
#include <cctype>
#include <algorithm>
#include <cmath>
#include <vector>
#include <climits>
using namespace std; const int maxn = 2e5 + ;
int maxv[maxn * ]; void update (int p, int v, int o, int L, int R) {
int M = L + ((R - L) >> );
if (L == R) {
maxv[o] = v;
} else {
if (p <= M) {
update (p, v, o << , L, M);
} else {
update (p, v, (o << ) | , M + , R);
}
maxv[o] = max (maxv[o * ], maxv[o << | ]);
}
} int query (int ql, int qr, int o, int L, int R) {
int M = L + (R - L) / , ans = INT_MIN;
if (ql <= L && R <= qr) {
return maxv[o];
}
if (ql <= M) {
ans = max (ans, query (ql, qr, o << , L, M));
}
if (M < qr) {
ans = max (ans, query (ql, qr, o << | , M + , R));
}
return ans;
} int main () {
int n, ask_n, x, a, b;
char op[];
while (~scanf ("%d%d", &n, &ask_n)) {
memset (maxv, , sizeof(maxv));
for (int i = ; i <= n; ++ i) {
scanf ("%d", &x);
update (i, x, , , n);
} while (ask_n --) {
scanf ("%s %d %d", op, &a, &b); if (op[] == 'Q') {
printf ("%d\n", query (a, b, , , n));
} else if (op[] == 'U') {
update (a, b, , , n);
}
}
}
return ;
}
【HDU1754】I Hate It(线段树)的更多相关文章
- hdu1754 I hate it线段树模板 区间最值查询
题目链接:这道题是线段树,树状数组最基础的问题 两种分类方式:按照更新对象和查询对象 单点更新,区间查询; 区间更新,单点查询; 按照整体维护的对象: 维护前缀和; 维护区间最值. 线段树模板代码 # ...
- HDU1754 I hate it(线段树 单点修改)
好久没打线段树,来一道练练手,但说句实话,I really hate it!!!! 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感. 不管 ...
- hdu1754 I Hate It (线段树 更新点的值)
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- hdu1754 I Hate It(线段树单点更新,区间查询)
传送门 有更新单个学生成绩和查询某个区间内学生成绩最大值两种操作 线段树代码 #include<bits/stdc++.h> using namespace std; +; using n ...
- HDU1754 I hate it_线段树(入门级别)
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU-1754 I Hate It(线段树,区间最大值)
很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问.当然,老师 ...
- HDU1754 —— I Hate It 线段树 单点修改及区间最大值
题目链接:https://vjudge.net/problem/HDU-1754 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感. 不管你喜不喜 ...
- [HDU1754]I Hate It线段树裸题
http://acm.hdu.edu.cn/showproblem.php?pid=1754 解题关键:刚开始死活超时,最后发现竟然是ch,和t1.t2每次循环都定义的锅,以后养成建全局变量的习惯. ...
- I Hate It(hdu1754)(线段树区间最大值)
I Hate It hdu1754 Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- [线段树]HDU-1754板子题入门ver
HDU-1754 线段树数组请开到四倍 众所周知数组开小会导致re tle wa等一系列问题orz 板子就是板子,数组从零开始或是从一开始都没什么问题,就是2*root+1还是2*root+2的问题. ...
随机推荐
- c语言指针与结构体之内存动态分配
struct dangdangtest { ]; ]; ]; int num; int bugnum; ]; ]; double RMB; }; void main2() { //struct dan ...
- mongodb 更新数组出现can't append to array using string field name
数据库内容大概如下: { _id:, "hero_list" : { " : { , , "equip" : [ [ ], [ ], [ ], { , ...
- Android-67-Tomcat启动出错:Server Tomcat v7.0 Server at localhost failed to start.
错误:Server Tomcat v7.0 Server at localhost failed to start.如图: 唉! ! !!图片上传不上去,悲哀啊!..仅仅能先写着错误提示语吧~~ ...
- Android开发小问题——java使用
2013-09-25 导语:离上次写博客有点久了,这次写两个开发中解决的问题吧. 正文: 1.ArrayList<E>使用remove问题: 2.字符串映射到函数运行方法: ==== 1. ...
- Composer 基本指令操作使用
Composer 基本指令操作使用 註: 若 composer.phar 改名為 composer, 請自行將 "php composer.phar" 替換成 "comp ...
- [Cycle.js] Making our toy DOM Driver more flexible
Our previous toy DOM Driver is still primitive. We are only able to sends strings as the textContent ...
- [Cycle.js] Generalizing run() function for more types of sources
Our application was able to produce write effects, through sinks, and was able to receive read effec ...
- Linq 关键字
from var lowNums = from num in numbers where num < 5 select num; numbers 是数 ...
- C++中的数组和指针
#include <iostream> #include <set> using namespace std; int main() { ] = {,,,,,}; ]; p = ...
- 关于Repeater中绑定的控件不触发ItemCommand事件
今天遇到 在repeater 中使用一个button,点击button然后跳转另外一个页面. html. <asp:Repeater ID="repeater" runat= ...