【hdu 1754】I Hate It 【线段树 训练1】
来源:互联网 发布:淘宝李宁是真的吗 编辑:程序博客网 时间:2024/05/19 03:23
Description
很多学校流行一种比较的习惯。老师们很喜欢询问,从某某到某某当中,分数最高的是多少。
这让很多学生很反感。
不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问。当然,老师有时候需要更新某位同学的成绩。
Input
本题目包含多组测试,请处理到文件结束。
在每个测试的第一行,有两个正整数 N 和 M ( 0
#include<cstdio>#include<iostream>#include<cstring>#include<cmath>using namespace std;int n,m;#define maxn 200001struct tree{ int l,r; int v;}e[maxn*4];int max(int a,int b){ return a>b?a:b;}void pushup(int u){ e[u].v = max(e[u<<1].v,e[u<<1|1].v);}void build(int u,int l,int r){ e[u].l=l; e[u].r=r; if(l==r) { scanf("%d",&e[u].v); return; } int mid = (l+r)>>1; build(u<<1,l,mid); build(u<<1|1,mid+1,r); pushup(u); }char read(){ char c = getchar(); while(c!='U'&&c!='Q')c=getchar(); return c;}void update(int u,int l,int r,int x,int add){ if(r==l) { e[u].v = add; return; } int mid = (l+r)>>1; if(x<=mid)update(u<<1,l,mid,x,add); else update(u<<1|1,mid+1,r,x,add); pushup(u);}int query(int u,int l,int r,int x,int y){ if(l==x&&y==r) { return e[u].v; } int mid = (l+r)>>1; if(y<=mid)return query(u<<1,l,mid,x,y); else if(x>mid)return query(u<<1|1,mid+1,r,x,y); else { return max(query(u<<1,l,mid,x,mid),query(u<<1|1,mid+1,r,mid+1,y)); }}int main(){ int a,b; while(scanf("%d%d",&n,&m)==2) { build(1,1,n); for(int i=1;i<=m;i++) { int ch = read(); if(ch=='Q') { scanf("%d%d",&a,&b); printf("%d\n",query(1,1,n,a,b)); }else { scanf("%d%d",&a,&b); update(1,1,n,a,b); } } } return 0;}
1 0
- 【hdu 1754】I Hate It 【线段树 训练1】
- 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(线段树)
- UVALive6969 ZOJ3819 Average Score
- 错误
- Spark排错与优化
- 【Spring】基于注解的Spring AOP的配置和使用
- android adb push 与 adb install的比较
- 【hdu 1754】I Hate It 【线段树 训练1】
- 17.1.1.9 Introducing Additional Slaves to an Existing Replication Environment 引入额外的Slaves 到一个存在的复制
- ssm遇到css样式和js加载不出来
- 读书笔记二——第一章《面向服务的体系架构SOA》上
- C++虚函数、纯虚函数、虚基类
- 【HDU5740 2016 Multi-University Training Contest 2G】【二分图染色+费用流+路径输出】Glorious Brilliance 最少交换次数使得相邻点颜色
- HDU 4596 - Yet another end of the world(扩展欧几里得)
- QQ与共享
- 解决Visual Studio 2010新建工程时出现『1>LINK : fatal error LNK1123: failure during conversion to COFF: file in