HDU - 1754 I Hate It (线段树点修改求最大值)
题意:有N个学生M条操作,0<N<=200000,0<M<5000,要么查询某区间内学生的最高分,要么更改某学生的成绩。
分析:原理和线段树点修改求和类似。
#include<cstdio>
#include<map>
#include<iostream>
#include<cstring>
using namespace std;
const int MAXN = 200000 + 10;
int a[MAXN];
int ma[MAXN << 2];
void build(int id, int L, int R){
if(L == R){
ma[id] = a[L];
}
else{
int mid = L + (R - L) / 2;
build(id << 1, L, mid);
build(id << 1 | 1, mid + 1, R);
ma[id] = max(ma[id << 1], ma[id << 1 | 1]);
}
}
void update(int pos, int id, int L, int R, int value){
if(L == R){
ma[id] = value;
}
else{
int mid = L + (R - L) / 2;
if(pos <= mid) update(pos, id << 1, L, mid, value);
else update(pos, id << 1 | 1, mid + 1, R, value);
ma[id] = max(ma[id << 1], ma[id << 1 | 1]);
}
}
int query(int l, int r, int id, int L, int R){
if(l <= L && R <= r){
return ma[id];
}
int ans = 0;
int mid = L + (R - L) / 2;
if(l <= mid) ans = max(ans, query(l, r, id << 1, L, mid));
if(r > mid) ans = max(ans, query(l, r, id << 1 | 1, mid + 1, R));
return ans;
}
int main(){
int N, M;
while(scanf("%d%d", &N, &M) == 2){
memset(a, 0, sizeof a);
memset(ma, 0, sizeof ma);
for(int i = 1; i <= N; ++i){
scanf("%d", &a[i]);
}
build(1, 1, N);
while(M--){
getchar();
char c;
scanf("%c", &c);
int x, y;
scanf("%d%d", &x, &y);
if(c == 'Q'){
printf("%d\n", query(x, y, 1, 1, N));
}
else if(c == 'U'){
update(x, 1, 1, N, y);
}
}
}
return 0;
}
HDU - 1754 I Hate It (线段树点修改求最大值)的更多相关文章
- HDU 1754 I Hate It 线段树单点更新求最大值
题目链接 线段树入门题,线段树单点更新求最大值问题. #include <iostream> #include <cstdio> #include <cmath> ...
- HDU 1754 I Hate It 线段树 单点更新 区间最大值
#include<iostream> #include<string> #include<algorithm> #include<cstdlib> #i ...
- hdu 1754 I Hate It 线段树 点改动
// hdu 1754 I Hate It 线段树 点改动 // // 不多说,裸的点改动 // // 继续练 #include <algorithm> #include <bits ...
- 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 ...
- HDU 1754 I Hate It (线段树)
题意:略. 析:裸的线段树. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include < ...
- HDU 1754 I Hate It(线段树区间查询,单点更新)
描述 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感.不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问.当然,老 ...
- HDU 1754 I Hate It (线段树)
题目链接 Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就是按照老 ...
随机推荐
- ES查询不重复的数据
GET ana-apk/_search #查询不重复的mac地址{ "size": 10, "aggs": { "MAC": { ...
- requests 用法小速记
Request库安装方法 Request官网 使用管理员权限启动 command控制台(win+X 命令提示符(管理员)) 使用pip安装requests库(默认配置好python以及pip的环境变量 ...
- 当在命令行中执行virtualenv venv时报此错误:'utf-8' codec can't decode byte 0xd5 in position 38: invalid continuation by
1.windows中安装虚拟环境virtualenv时, 当在命令行中执行virtualenv venv时报此错误:'utf-8' codec can't decode byte 0xd5 in po ...
- 误删Django的model中的表解决办法
误删Django的model中的表解决办法 1.model里面的表格实际的操作都在migrations文件夹中,里面记录了操作过程,当在database和model中删除表格时要注意初始化数据库时会报 ...
- Beautisoup库
所看视频: https://www.bilibili.com/video/av9784617/?p=34 一, Beautifulsoup是一个可以从HTML或XML文件中提取数据的Python库,它 ...
- git push的时候报错: Out of memory, malloc failed (tried to allocate 82037333 bytes)
原因:上传的文件过大,这里我上传的文件有10G+所以报了上面的错误 解决方法:依次运行:git config --global pack.threads 1 git,git config --glob ...
- 1.WEB安全概述
一.WEB常见的安全性问题简介 XSS(Cross-Site Scripting):跨站脚本攻击漏洞 CSRF(Cross-site request forgery):跨站请求伪造 文件上传漏洞 SQ ...
- nginx 跨域设置
upstream nginx { ip_hash; server weight=; server weight=; } server { listen ; server_name www.enjoy. ...
- ABC155D - Pairs
本题的模型是典型的求第k小问题,这个问题有2个不一样的点,一是任意选出2个数,不能是同一个,二是这个题有负数,那我们在原有的基础上就需要特判这两点,经典模型是2个数组相乘,此处是1个,那么一样可以枚举 ...
- uniGUI页面标题和页面背景的更改(03)
---------------------------------------------------------------------------------------------------- ...