【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语言sizeof与strlen的区别
#include <stdio.h> #include <stdlib.h> #include <string.h> //strlen与sizeof的区别 //st ...
- 第32讲 UI组件之 时间日期控件DatePicker和TimePicker
第32讲 UI组件之 时间日期控件DatePicker和TimePicker 在Android中,时间日期控件相对来说还是比较丰富的.其中, DatePicker用来实现日期输入设置, Time ...
- hdu 5159 Card (期望)
Problem Description There are x cards on the desk, they are numbered from 1 to x. The score of the c ...
- 20个经典bootsrtap后台html站点模板推荐
今天为大家推荐20款不同风格的Bootstrap后台管理模板,每一款都经典可用,能预览和下载,保证让你挑得眼花缭乱. 1,Simpli flag蓝色 Simpli Flat蓝色管理模板是一款採用Fla ...
- MDM 证书申请流程(vendor及customer)
整个流程分为两部分:vendor,customer. 一.Vendor 1.成为一个 MDM Vendor 1) 首先你须要拥有一个 Apple Enterprise account($299/年). ...
- (转)单例模式(Singleton)
首先来明确一个问题,那就是在某些情况下,有些对象,我们只需要一个就可以了, 比如,一台计算机上可以连好几个打印机,但是这个计算机上的打印程序只能有一个, 这里就可以通过单例模式来避免两个打印作业同时输 ...
- js过滤
datagrid: loadFilter: function (data) { return loadFilter(data); ...
- ajaxFileUpload js判断类型
function ajaxFileUpload() { var File_box = document.getElementById('V_file'); var extend = Fil ...
- asp.net 参数形式写sql
OracleConnection conn = c.GetConnection(); OracleCommand cmd = new OracleCommand(); ...
- C#图像处理(4):图像的剪裁
图像的剪裁方法,从中间剪裁返回剪裁后的左右两页,方法实现如下: /// <summary> /// 图片裁剪,返回左右两页 /// </summary> /// <par ...