HDU-1754 I Hate It(线段树)
来源:互联网 发布:上古卷轴5跳出优化补丁 编辑:程序博客网 时间:2024/06/06 13:17
阿里云-云翼计划礼上加礼#——买六个月送域名代金券!
I Hate It
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 55851 Accepted Submission(s): 21792
Problem Description
很多学校流行一种比较的习惯。老师们很喜欢询问,从某某到某某当中,分数最高的是多少。
这让很多学生很反感。
不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问。当然,老师有时候需要更新某位同学的成绩。
Input
本题目包含多组测试,请处理到文件结束。
在每个测试的第一行,有两个正整数 N 和 M ( 0
#include <iostream>#include <math.h>#include <stdlib.h>#include <string.h>using namespace std;int c[4000001];int n,m;char a;int x,y;int max(int x,int y){ return x>y?x:y;}void PushUp(int node){ c[node]=max(c[node<<1],c[node<<1|1]);}void build(int node,int begin,int end){ if(begin==end) { scanf("%d",&c[node]); return; } int m=(begin+end)>>1; build(node<<1,begin,m); build(node<<1|1,m+1,end); PushUp(node);}void Update(int node,int begin,int end,int ind,int num){ if(begin==end) { c[node]=num; return; } int m=(begin+end)>>1; if(ind<=m) Update(node<<1,begin,m,ind,num); else Update(node<<1|1,m+1,end,ind,num); PushUp(node);}int Query(int node,int begin,int end,int left,int right){ if(left<=begin&&end<=right) return c[node]; int m=(begin+end)>>1; int ret=0; if(left<=m) ret=max(ret,Query(node<<1,begin,m,left,right)); if(right>m) ret=max(ret,Query(node<<1|1,m+1,end,left,right)); return ret;}int main(){ while(scanf("%d%d",&n,&m)!=EOF) { build(1,1,n); for(int i=0;i<m;i++) { getchar(); scanf("%c",&a); scanf("%d%d",&x,&y); if(a=='Q') { printf("%d\n",Query(1,1,n,x,y)); } else { Update(1,1,n,x,y); } } } return 0;}
0 0
- HDU 1754 I Hate It 线段树
- [hdu] 1754 I hate it -- 线段树
- hdu 1754 -- I Hate It (线段树)
- HDU 1754 I Hate It 线段树
- 线段树 hdu 1754 I Hate It
- HDU 1754 I Hate It(线段树)
- hdu 1754 (线段树)I Hate It
- hdu-1754 I Hate It 线段树
- HDU--1754 -- I Hate It [线段树]
- 【线段树】hdu 1754 I hate it
- hdu - 1754 I Hate It(线段树)
- HDU--1754--I Hate It--线段树
- HDU-1754 I Hate It 线段树
- hdu 1754 I Hate It 线段树
- HDU-1754-I Hate It(线段树)
- HDU 1754 I Hate It (线段树)
- hdu 1754 I hate it(线段树)
- 【HDU】 1754 I Hate It 线段树
- SSDB开源 NoSQL 数据库
- c++11中正则表达式的使用
- 树形菜单的二叉链表实现--数据库实现(增删改存储过程实现)
- 一起talk C栗子吧(第八十五回:C语言实例--使用信号进行进程间通信二)
- QlikView+R(以iris数据作为案例)(一)
- HDU-1754 I Hate It(线段树)
- hdu3552I can do it!(贪心)
- Sql Server 向上取整,向下取整,四舍五入
- 151Reverse Words in a String
- dig安装
- 运行rails server 出现There was an error while trying to load the gem 'uglifier'. (Bundler::GemRequireErr
- Python学习笔记2-Python神奇的语法和格式化输出
- 理解C++的链接:C++内链接与外链接的意义
- Android开发者网址导航