题意:很多学校流行一种比较的习惯。老师们很喜欢询问,从某某到某某当中,分数最高的是多少。这让很多学生很反感。不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问。当然,老师有时候需要更新某位同学的成绩。

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 单点更新的更多相关文章

  1. HDU 1754 单点更新,求区间最大值

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  2. hdu 1754(单点更新 ,区间最大值)

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  3. HDU 2795 单点更新,区间优先查找(想法)

    Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  4. HDU 1166 单点更新,区间求和

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  5. hdu 1166 (单点更新+区间求和+裸题)

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissi ...

  6. hdu 1754 I Hate It (线段树功能:单点更新和区间最值)

    版权声明:本文为博主原创文章.未经博主同意不得转载.vasttian https://blog.csdn.net/u012860063/article/details/32982923 转载请注明出处 ...

  7. HDU 1754 I Hate It 线段树(单点更新,成段查询)

    题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=1754 题解: 单点更新,成段查询. 代码: #include<iostream> ...

  8. HDU 1754 I Hate It 线段树单点更新求最大值

    题目链接 线段树入门题,线段树单点更新求最大值问题. #include <iostream> #include <cstdio> #include <cmath> ...

  9. 【HDU】1754 I hate it ——线段树 单点更新 区间最值

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

随机推荐

  1. iphone6 wifi自动断开 tplink

    这样设置就好了,不会自动断开 了

  2. jquery设置和获得checkbox选中问题

    1.设置checkbox选中: //选中多选框 checkbox=$("#agentinfo input[name='veri[]']"); //循环多选框中的值 checkbox ...

  3. zabbix 汉化

    zabbix2.x的版本自带汉化,3.x的版本也可以通过修改配置文件强制使用自带的汉化,但是不管哪种,翻译的精准度令人费解:偶然发现一个专门翻译zabbix的网站https://www.zabbix. ...

  4. Linux创建线程

    #include"stdio.h" #include"pthread.h" #include"unistd.h" ; void *creat ...

  5. 动态插入、添加删除表格行的JS代码

    <html> <head> <title>Table对象的方法</title> <script language="JavaScript ...

  6. mlecms v2.2版权

    inc\tools\smarty 下的Smarty.class.php文件. 找到 187行左右 我们会发现原来的  $dopud =$_template->libfile($dopud);已经 ...

  7. 用开源Look&Feel (Substance)写 漂亮的Swing应用程序

    今天用Swing 做了一个模仿QQ2009的登录界面,用到了开源的Look&Feel (Substance),在使用的过程中遇到了一些问题,也学到了一些技巧.Substance (https: ...

  8. js中的getAttribute方法使用示例

    getAttribute()方法是一个函数.它只有一个参数——你打算查询的属性的名字,下面为大家介绍下其具体的使用   getAttribute()方法 至此,我们已经向大家介绍了两种检索特定元素节点 ...

  9. 导出Excel之Epplus使用教程4(其他设置)

    导出Excel之Epplus使用教程1(基本介绍) 导出Excel之Epplus使用教程2(样式设置) 导出Excel之Epplus使用教程3(图表设置) 导出Excel之Epplus使用教程4(其他 ...

  10. POJ 1276 Cash Machine

    Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24213 Accepted: 8476 Descrip ...