kuangbin专题七 HDU1754 I Hate It (单点修改维护最大值)
这让很多学生很反感。
不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问。当然,老师有时候需要更新某位同学的成绩。
Input本题目包含多组测试,请处理到文件结束。
在每个测试的第一行,有两个正整数 N 和 M ( 0<N<=200000,0<M<5000 ),分别代表学生的数目和操作的数目。
学生ID编号分别从1编到N。
第二行包含N个整数,代表这N个学生的初始成绩,其中第i个数代表ID为i的学生的成绩。
接下来有M行。每一行有一个字符 C (只取'Q'或'U') ,和两个正整数A,B。
当C为'Q'的时候,表示这是一条询问操作,它询问ID从A到B(包括A,B)的学生当中,成绩最高的是多少。
当C为'U'的时候,表示这是一条更新操作,要求把ID为A的学生的成绩更改为B。
Output对于每一次询问操作,在一行里面输出最高成绩。Sample Input
5 6
1 2 3 4 5
Q 1 5
U 3 6
Q 3 4
Q 4 5
U 2 9
Q 1 5
Sample Output
5
6
5
9
经过两道题的磨练,终于可以手搓了!细节需要注意一下
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
using namespace std;
#define FO freopen("in.txt","r",stdin);
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define debug(x) cout << "&&" << x << "&&" << endl;
#define lowbit(x) (x&-x)
#define mem(a,b) memset(a, b, sizeof(a));
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=;
const int inf = 0x3f3f3f3f;
ll powmod(ll a,ll b) {ll res=;a%=mod;for(;b;b>>=){if(b&)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//head const int N=;
int n,m,a[N<<],maxx[N<<],pos,val,ans; void Pushup(int rt) {
maxx[rt]=max(maxx[rt<<],maxx[rt<<|]);
} void build(int rt,int L,int R) {
if(L==R) {
scanf("%d",&a[rt]);
maxx[rt]=a[rt];//这里是rt的维护信息
return;
}
int mid=(L+R)>>;
build(rt<<,L,mid);
build(rt<<|,mid+,R);
Pushup(rt);
} void Updata(int rt,int L,int R,int pos,int val) {
if(L==R) {//修改
a[rt]=val;
maxx[rt]=a[rt];
return;
}
int mid=(L+R)>>;
if(pos<=mid) Updata(rt<<,L,mid,pos,val);
else Updata(rt<<|,mid+,R,pos,val);
Pushup(rt);
} void Query(int rt,int L,int R,int l,int r) {//维护最大值
if(L>=l&&R<=r) {
ans=max(ans,maxx[rt]);
return;
}
int mid=(L+R)>>;
if(l<=mid) Query(rt<<,L,mid,l,r);
if(r>mid) Query(rt<<|,mid+,R,l,r);
} int main() {
while(~scanf("%d%d",&n,&m)) {
build(,,n);
char s[];
while(m--) {
ans=-;
scanf("%s%d%d",s,&pos,&val);
if(s[]=='Q') {
Query(,,n,pos,val);
printf("%d\n",ans);
} else Updata(,,n,pos,val);
}
}
}
kuangbin专题七 HDU1754 I Hate It (单点修改维护最大值)的更多相关文章
- kuangbin专题七 HDU1540 Tunnel Warfare (前缀后缀线段树)
During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast a ...
- kuangbin专题七 POJ3468 A Simple Problem with Integers (线段树或树状数组)
You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of op ...
- kuangbin专题七 HDU1166 敌兵布阵 (线段树或树状数组)
C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况.由于 ...
- kuangbin专题七 HDU3974 Assign the task (dfs时间戳建树)
There is a company that has N employees(numbered from 1 to N),every employee in the company has a im ...
- kuangbin专题七 ZOJ1610 Count the Colors (灵活线段树)
Painting some colored segments on a line, some previously painted segments may be covered by some th ...
- kuangbin专题七 HDU4027 Can you answer these queries? (线段树)
A lot of battleships of evil are arranged in a line before the battle. Our commander decides to use ...
- kuangbin专题七 POJ3264 Balanced Lineup (线段树最大最小)
For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One d ...
- kuangbin专题七 HDU1698 Just a Hook (区间设值 线段树)
In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes. T ...
- HDU 1166 【线段树 || 树状数组,单点修改 维护区间和】
题目链接 HDU 1166 大概题意: 第一行一个整数T,表示有T组数据.每组数据第一行一个正整数N(N<=50000),表示敌人有N个工兵营地,接下来有N个正整数,第i个正整数ai代表第i个工 ...
随机推荐
- 应用HTMLTestRunner整合测试报告
为了便于测试脚本的维护,以及更多测试用例的管理,于是根据上次学习的HTMLTestRunner生成的测试报告,今天将对其进行整理.我们之前使用 TestSuite 只是在一个.py 文件里添加多个测试 ...
- 2015.1.15 利用航线id取所有点的函数创建视图
1.根据航路id取所有航路点的函数 create or replace function alinepnts(alid in number) return tab_airline_pnt is --返 ...
- IDEA中Git实战
工作中多人使用版本控制软件协作开发,常见的应用场景归纳如下: 假设小组中有两个人,组长小张,组员小袁 场景一:小张创建项目并提交到远程Git仓库 场景二:小袁从远程Git仓库上获取项目源码 场景三:小 ...
- 免安装Oracle客户端使用PL/SQL连接Oracle
只需要在Oracle下载一个叫Instant Client Package的软件就可以了,这个软件不需要安装,只要解压就可以用了,很方便,就算重装了系统还是可以用的. 下载地址:http://www. ...
- PHP通过加锁实现并发情况下抢码功能
本文基于php语言使用加锁实现并发情况下抢码功能,特定时间段开放抢码并不允许开放的码重复: 需求:抢码功能 要求: 1.特定时间段才开放抢码: 2.每个时间段放开的码是有限的: 3.每个码不允许重复: ...
- jquery datatable设置垂直滚动后,表头(th)错位问题
jquery datatable设置垂直滚动后,表头(th)错位问题 问题描述: 我在datatable里设置:"scrollY": '300px',垂直滚动属性后,表头的宽度就会 ...
- SSM项目连接远程Linux服务器的mysql 启动tomcat卡在了 Initializing Spring root WebApplicationContext
网上查了原因, linux下mysql访问速度缓慢并且ssh连接缓慢的原因 解决办法: 1.linux ssh连接慢 最近发现ssh连接的时候却很慢,ping的速度非常好,让人误以为是ssh连接不上. ...
- Centos7安装mysql缺乏yum源怎么安装
找到mysql5.6的centos的repo源,终于解决mysql的安装问题: 1.确保centos安装了wget,没有的话安装wget 1 yum install wget 2.下载mysql的 ...
- ROS Learning-026 (提高篇-004 A Mobile Base-02) 控制移动平台 --- “分封制”
ROS 提高篇 之 A Mobile Base-02 - 控制移动平台 - "分封制" 我使用的虚拟机软件:VMware Workstation 11 使用的Ubuntu系统:Ub ...
- Luogu 1081 [NOIP2012] 开车旅行
感谢$LOJ$的数据让我调掉此题. 这道题的难点真的是预处理啊…… 首先我们预处理出小$A$和小$B$在每一个城市的时候会走向哪一个城市$ga_i$和$gb_i$,我们有链表和平衡树可以解决这个问题( ...