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个工 ...
随机推荐
- 使用jmx4perl和j4psh接管Jolokia
在ActiveMQ的API中,内置了Jolokia . 可以使用jmx4perl来安装: $ perl -MCPAN -e shell Terminal does not support AddHis ...
- Dev控件GridControl实现CheckBox列和ComBox列
1.在sql语句中添加空白行,如select c1,c2 null c3 from xxx; 2.将sql语句查询结果与gdc绑定CmmFrm.BestFitGridViewColumnsWidth( ...
- 问题:oracle select into;结果:oracle SELECT INTO 和 INSERT INTO SELECT 两种表复制语句详解
oracle SELECT INTO 和 INSERT INTO SELECT 两种表复制语句详解 (2011-07-08 08:59:47) 转载▼ 标签: it 分类: oracle 我们经常会遇 ...
- myeclipse10启动service窗口报异常
1:找到与之对应的tomcat: 2:删掉“.metadata/.plugins/org.eclipse.core.runtime/.settings/ com.genuitec.eclipse.as ...
- WebRTC的拥塞控制技术<转>
转载地址:http://www.jianshu.com/p/9061b6d0a901 1. 概述 对于共享网络资源的各类应用来说,拥塞控制技术的使用有利于提高带宽利用率,同时也使得终端用户在使用网络时 ...
- JAVA基础知识总结5(面向对象特征之一:继承)
继 承: 1:提高了代码的复用性. 2:让类与类之间产生了关系,提供了另一个特征多态的前提. 父类的由来:其实是由多个类不断向上抽取共性内容而来的. JAVA只支持单继承.java虽然不直接支持多继承 ...
- (内存地址hashcode与对象内容hashcode)分析== 和 equal()方法
==.equals()和hashCode()字符串测试 1.hashCode() 是根据 内容 来产生hash值的 2.System.identityHashCode() 是根据 内存地址 来产生ha ...
- linux 监控内存介绍
一:系统监控:1.对cpu的监测:查看进程占用内存情况 top pid user PRI NI size RSS share stat 进程号 进程所属用户 优先级 优先级 进程所占空间 使用物理内存 ...
- MyBatis02 MyBatis基础知识之Mapper映射器
1 Mapper映射器是什么 是符合映射文件要求的接口 接口要求 a. 方法名要与sql的id一致. b. 方法的参数类型要与parameterType一致. c. 方法的返回类型要与resultTy ...
- sleep()和usleep()
函数名: sleep头文件: #include <windows.h> // 在VC中使用带上头文件 #include <unistd.h> // 在gcc编译 ...