博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 1754 I Hate It线段树单点替换,区间最值
阅读量:4205 次
发布时间:2019-05-26

本文共 2206 字,大约阅读时间需要 7 分钟。

I Hate It

Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 70170    Accepted Submission(s): 27173
Problem Description
很多学校流行一种比较的习惯。老师们很喜欢询问,从某某到某某当中,分数最高的是多少。
这让很多学生很反感。
不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问。当然,老师有时候需要更新某位同学的成绩。
 
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 61 2 3 4 5Q 1 5U 3 6Q 3 4Q 4 5U 2 9Q 1 5
 
Sample Output
5659       
Hint
Huge input,the C function scanf() will work better than cin
#include
#include
#include
#include
using namespace std; const int maxn=200000+5; using namespace std; int a[maxn*4]; const int INF=0x3f3f3f3f; void PushUp(int i) { a[i]=max(a[i*2],a[i*2+1]); } void build(int i,int l,int r) { if(l==r) { scanf("%d",&a[i]); return; } int m=(l+r)/2; build(i*2,l,m); build(i*2+1,m+1,r); PushUp(i); } int query(int ql,int qr,int i,int l,int r) { if(ql<=l&&r<=qr) return a[i]; int m=(l+r)/2; int maxx=-INF; if(ql<=m) maxx=max(maxx,query(ql,qr,i*2,l,m)); if(qr>m) maxx=max(maxx,query(ql,qr,i*2+1,m+1,r)); return maxx; } void update(int id,int val,int i,int l,int r) { if(l==r) { a[i]=val; return; } int m=(l+r)/2; if(id<=m) update(id,val,i*2,l,m); else update(id,val,i*2+1,m+1,r); PushUp(i); } int main() { int n,m; char str[10]; int x,y; while(cin>>n>>m) { build(1,1,n); while(m--) { scanf("%s%d%d",str,&x,&y); if(str[0]=='Q') printf("%d\n",query(x,y,1,1,n)); else update(x,y,1,1,n); } } return 0; }

转载地址:http://jsali.baihongyu.com/

你可能感兴趣的文章
【Kernel】pid 与 tgid
查看>>
【Error】make LKM时 找不到符号
查看>>
【转载】【C语言】浅析C语言之uint8_t / uint16_t / uint32_t /uint64_t
查看>>
【转载】yum update 自动忽略内核更新
查看>>
【maven】打包jar上传到服务器运行
查看>>
关闭centos wayland
查看>>
【Error】chsh: PAM: Authentication failure
查看>>
【Error】zsh历史记录丢失
查看>>
解析漏洞总结
查看>>
有趣的二进制 读书笔记
查看>>
记一次vmware磁盘扩容part2:真正扩展根目录
查看>>
【Error】zsh: corrupt history file /home/myusername/.zsh_history
查看>>
记一次编译linux 2.6 和4.10内核源码
查看>>
【Error】couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied) [duplicate]
查看>>
qemu 文件系统制作:自己制作根目录和应用程序 + busybox
查看>>
关闭CSDN广告必备插件:adblock plus
查看>>
【pwnable.kr】fd
查看>>
【pwnable.kr】 collision
查看>>
【pwnable.kr】bof
查看>>
【pwnable.kr】flag
查看>>