I Hate It

Time Limit: 1 Sec  Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=1754

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 6 1 2 3 4 5 Q 1 5 U 3 6 Q 3 4 Q 4 5 U 2 9 Q 1 5

Sample Output

5 6 5 9

HINT

题意

线段树RMQ,单点更新,区间查询最大值

题解:

线段树RMQ,单点更新,区间查询最大值

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 205001
#define mod 10007
#define eps 1e-9
//const int inf=0x7fffffff; //无限大
const int inf=0x3f3f3f3f;
/*
inline ll read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
*/
//************************************************************************************** int n,q,a[maxn];
struct data{
int l,r,mn;
}tr[maxn*];
void build(int k,int s,int t)
{
tr[k].l=s;tr[k].r=t;
if(s==t){tr[k].mn=a[s];return;}
int mid=(s+t)>>;
build(k<<,s,mid);
build(k<<|,mid+,t);
tr[k].mn=max(tr[k<<].mn,tr[k<<|].mn);
}
int ask(int k,int s,int t)
{
int l=tr[k].l,r=tr[k].r;
if(s==l&&t==r)return tr[k].mn;
int mid=(l+r)>>;
if(t<=mid)return ask(k<<,s,t);
if(s>mid)return ask(k<<|,s,t);
return max(ask(k<<,s,mid),ask(k<<|,mid+,t));
}
void update(int k,int x,int y)
{
int l=tr[k].l,r=tr[k].r;
if(l==r){tr[k].mn=y;return;}
int mid=(l+r)>>;
if(x<=mid)update(k<<,x,y);
if(x>mid)update(k<<|,x,y);
tr[k].mn=max(tr[k<<].mn,tr[k<<|].mn);
}
int main()
{
//ios_base::sync_with_stdio(0);cin.tie(0);
while(scanf("%d%d",&n,&q)!=EOF)
{
memset(a,,sizeof(a));
memset(tr,,sizeof(tr));
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
build(,,n);
for(int i=;i<=q;i++)
{
char t;
int x,y;
cin>>t;
scanf("%d%d",&x,&y);
if(t=='Q')printf("%d\n",ask(,x,y));
else update(,x,y);
}
}
return ;
}

HDU 1754 I Hate It 线段树RMQ的更多相关文章

  1. hdu 1754 I Hate It 线段树 点改动

    // hdu 1754 I Hate It 线段树 点改动 // // 不多说,裸的点改动 // // 继续练 #include <algorithm> #include <bits ...

  2. HDU 1754 I Hate It(线段树之单点更新,区间最值)

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

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

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

  4. HDU 1754 I Hate It(线段树单点替换+区间最值)

    I Hate It [题目链接]I Hate It [题目类型]线段树单点替换+区间最值 &题意: 本题目包含多组测试,请处理到文件结束. 在每个测试的第一行,有两个正整数 N 和 M ( 0 ...

  5. HDU 1754 I Hate It (线段树)

    题意:略. 析:裸的线段树. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include < ...

  6. HDU 1754 I Hate It(线段树区间查询,单点更新)

    描述 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感.不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问.当然,老 ...

  7. HDU 1754 I Hate It (线段树)

    题目链接 Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就是按照老 ...

  8. hdu 1754 I Hate It 线段树基础题

    Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求, ...

  9. hdu 1754 I Hate It(线段树水题)

    >>点击进入原题测试<< 思路:线段树水题,可以手敲 #include<string> #include<iostream> #include<a ...

随机推荐

  1. Linux内核跟踪之syscall tracer 【转】

    转自:http://blog.chinaunix.net/uid-20543183-id-1930847.html ------------------------------------------ ...

  2. Linux下配置镜像源

    清华大学地址: https://mirrors.tuna.tsinghua.edu.cn 选择对应ubuntu的版本 在linux下用终端敲 cd /etc/apt/source.list 把里面的内 ...

  3. ubuntu使用百度云盘插件

    Firefox 插件地址 https://addons.mozilla.org/zh-CN/firefox/addon/baidu-pan-exporter/ 安装后重启Firefox,然后百度云下载 ...

  4. 002_IO磁盘深入理解

    一.如何测试云硬盘 https://www.ustack.com/blog/how-benchmark-ebs/#fio

  5. scala中“_”的用法

    参见链接 http://blog.csdn.net/i6448038/article/details/50017427

  6. css-css背景

    CSS 允许应用纯色作为背景,也允许使用背景图像创建相当复杂的效果 一:背景色background-color 属性 p {background-color: gray;} 二:背景图像 backgr ...

  7. No.13 selenium for python 单选框和复选框

    单选框 radio 点击图标,可以获取HTML中定位. 使用普通的ID定位就可以了 定位到指定元素,然后使用clicd选中即可 复选框 checkbox 勾选单个框,跟单选框一样,定位后点击就可以了 ...

  8. JavaScript 中的回调函数

    原文:http://javascriptissexy.com/ 翻译:http://blog.csdn.net/luoweifu/article/details/41466537 [建议阅读原文,以下 ...

  9. C# Except

    我们往往需要把一个列表中,去除另外一个列表的元素,C#提供了很好的方法,Except. 但是往往不小心就掉进坑里了. 看下面的代码: static void Main(string[] args) { ...

  10. Action(8):Error-26608:HTTP Status-Code=504(Gateway Time-out)

    Action(8):Error-26608:HTTP Status-Code=504(Gateway Time-out) 若出现如下图问题, 1.在Vuser Generator中的Tools---& ...