很多学校流行一种比较的习惯。老师们很喜欢询问,从某某到某某当中,分数最高的是多少。
这让很多学生很反感。

不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问。当然,老师有时候需要更新某位同学的成绩。

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 (单点修改维护最大值)的更多相关文章

  1. kuangbin专题七 HDU1540 Tunnel Warfare (前缀后缀线段树)

    During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast a ...

  2. 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 ...

  3. kuangbin专题七 HDU1166 敌兵布阵 (线段树或树状数组)

    C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况.由于 ...

  4. 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 ...

  5. kuangbin专题七 ZOJ1610 Count the Colors (灵活线段树)

    Painting some colored segments on a line, some previously painted segments may be covered by some th ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. HDU 1166 【线段树 || 树状数组,单点修改 维护区间和】

    题目链接 HDU 1166 大概题意: 第一行一个整数T,表示有T组数据.每组数据第一行一个正整数N(N<=50000),表示敌人有N个工兵营地,接下来有N个正整数,第i个正整数ai代表第i个工 ...

随机推荐

  1. nfs cron shell 笔记

    1.nfs 2.crond 3.shell 1.准备环境: 防火墙 selinux 配置ip 2.安装软件 二进制 源码安装 3.改改配置文件 二进制:/etc/nginx/nginx.conf 源码 ...

  2. Python的安装以及路径的设置(python的下载地址:www.python.org)

    在有的Python版本中在安装时,我们的可以再安装时选择Python路径的自动配备 在选择python的安装程序的时候,我们尽量选择python的2.版本,因为随着Python的更新,Python的数 ...

  3. [Python Study Notes]堆叠柱状图绘制

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

  4. FOUC

    如果使用import方法对CSS进行导入,会导致某些页面在Windows 下的Internet Explorer出现一些奇怪的现象:以无样式显示页面内容的瞬间闪烁,这种现象称之为文档样式短暂失效(Fl ...

  5. solr replication原理探究

    原文出自:http://sbp810050504.blog.51cto.com/2799422/1423199 无论是垂直搜索,还是通用搜索引擎,对外提供搜索服务其压力都比较大,经常有垂直电商在做活动 ...

  6. C++——explicit

    explicit构造函数是用来防止隐式转换的.请看下面的代码: class Test1 { public: Test1(int n) { num=n; }//普通构造函数 private: int n ...

  7. 吐槽下linq to sql的分页功能

    在调试程序的时候发现一个非常奇怪的问题: 用使用linq分页,分页到第二页的时候,第二页里面有第一页里出现的数据,开始还以为是. linq语句写的有问题,调试半天,无解.后来发现是因为没有排序的缘故. ...

  8. Condition实现等待、通知

    使用Condition实现等待/通知: import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.L ...

  9. ubuntu16安装pylearn2 出现错误提示importerror:no module named six.moves

    由于市面上的一些教程时间比较早,入门学习时跟随教程安装容易出现各种错误,这些错误基本都是版本不同导致的 所以,我们安装过程中一定要指出包的版本,如果你已经遇到no module named six.m ...

  10. R: 用 R 查看、管理文件(夹)

    文件管理主要函数: list.files( ): 查看当前目录下文件. file.show( ): 显示文件. file.access( ): 查看文件是否可读可写. file.create( ): ...