hdu 1754 单点更新
题意:很多学校流行一种比较的习惯。老师们很喜欢询问,从某某到某某当中,分数最高的是多少。这让很多学生很反感。不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问。当然,老师有时候需要更新某位同学的成绩。
- 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
- 5
- 6
- 5
- 9
代码再次优化
- #include<cstdio>
- #include<iostream>
- #include<algorithm>
- #include<cstring>
- #include<cmath>
- #include<queue>
- using namespace std;
- int n,m,t;
- #define lson l,m,rt<<1
- #define rson m+1,r,rt<<1|1
- #define root 1,n,1
- #define m ((l+r)>>1)
- const int maxn=;
- int cow[maxn];
- int maxx[maxn<<],minn[maxn<<];
- int mmax=-,mmin=;
- void pushup(int rt){
- maxx[rt]=max(maxx[rt<<],maxx[rt<<|]);
- }
- void build(int l,int r,int rt){
- if(l==r){
- scanf("%d",&maxx[rt]);
- return;
- }
- build(lson);
- build(rson);
- pushup(rt);
- }
- void query(int L,int R,int l,int r,int rt) {
- if (L<=l&&r<=R){
- mmax=max(mmax,maxx[rt]);
- return;
- }
- int ret=;
- if(L<=m) query(L,R,lson);
- if(R>m) query(L,R ,rson);
- }
- void update(int pos,int val,int l,int r,int rt)
- {
- if(l==r) maxx[rt]=val;
- else
- {
- if(pos<=m) update(pos,val,lson);
- else update(pos,val,rson);
- pushup(rt);
- }
- }
- int main()
- {
- int i,j,k;
- #ifndef ONLINE_JUDGE
- freopen("1.in","r",stdin);
- #endif
- int q;
- while(scanf("%d%d",&n,&q)!=EOF)
- {
- build(root);
- while(q--)
- {
- char s[];
- scanf("%s",s);
- int a,b;
- if(s[]=='Q')
- {
- scanf("%d%d",&a,&b);
- mmax=-;
- query(a,b,root);
- printf("%d\n",mmax);
- }
- else
- {
- scanf("%d%d",&a,&b);
- update(a,b,root);
- }
- }
- }
- return ;
- }
hdu 1754 单点更新的更多相关文章
- HDU 1754 单点更新,求区间最大值
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- hdu 1754(单点更新 ,区间最大值)
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 2795 单点更新,区间优先查找(想法)
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 1166 单点更新,区间求和
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- hdu 1166 (单点更新+区间求和+裸题)
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissi ...
- hdu 1754 I Hate It (线段树功能:单点更新和区间最值)
版权声明:本文为博主原创文章.未经博主同意不得转载.vasttian https://blog.csdn.net/u012860063/article/details/32982923 转载请注明出处 ...
- HDU 1754 I Hate It 线段树(单点更新,成段查询)
题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=1754 题解: 单点更新,成段查询. 代码: #include<iostream> ...
- HDU 1754 I Hate It 线段树单点更新求最大值
题目链接 线段树入门题,线段树单点更新求最大值问题. #include <iostream> #include <cstdio> #include <cmath> ...
- 【HDU】1754 I hate it ——线段树 单点更新 区间最值
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
随机推荐
- WebService中方法的相关注意事项
2014-11-14 在WebService中定义方法,有一些注意的地方: (1) 方法上面需要增加 [WebMethod] 属性,标志该方法是一个WebService方法: (2)方法的返回值可以为 ...
- 繁华模拟赛 vicent的字符串
#include<iostream> #include<cstdio> #include<string> #include<cstring> #incl ...
- 繁华模拟赛 Vicent与游戏
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #i ...
- jquery 调用数据
<body> <div id="aa" style="">hello</div> <div class="b ...
- 畅通工程再续(MST)
畅通工程再续 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- (11)UI布局和分辨率适配
一.Cocos编辑器 自动布局系统主要涉及固定与拉伸属性: 如图,总共可以修改控件的上下左右四个图钉和中间的两个拉伸条六个属性. 效果 1.当打开其中的任意一个图钉时,当前节点与父节点的对应边 ...
- cocos基础教程(6)坐标与锚点讲解
坐标系详解 Cocos2d-x坐标系和OpenGL坐标系相同,都是起源于笛卡尔坐标系.原点为屏幕左下角,x向右,y向上. 世界坐标系(World Coordinate) VS 本地坐标系(Node L ...
- 备份还原mysql数据库
Windows下cmd命令行中备份还原mysql数据库 先cmd 上cd 到mysql的安装bin目录下,然后再运行下面的命令. 例如:cd C:\Program Files\MySQL\MySQL ...
- HNU 12826 Balloons Colors
题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12826&courseid=268 #include&l ...
- Linux常用指令(持续更新)
(这些文章都是从我的个人主页上粘贴过来的,大家也可以访问我的主页 www.iwangzheng.com) PP真的是一位很有姿势的程序猿,有这样的邻居真好,榜样啊. pwd 当前路径 df -kh ...