HDU 1754
成段更新 easy
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
using namespace std;
const int MM=;
int num[MM<<];
void buildtree(int l,int r,int id)
{
if(l==r)
{
scanf("%d",&num[id]);return;
}
else
{
int mid=(l+r)>>;
buildtree(l,mid,id<<);
buildtree(mid+,r,id<<|);
num[id]=max(num[id<<],num[id<<|]);
}
}
int query(int L,int R,int l,int r,int id)
{
int maxx=0x80000000;
if(L<=l&&r<=R)return num[id];
else
{
int mid=(l+r)>>;
if(L<=mid)
maxx=max(query(L,R,l,mid,id<<),maxx);
if(R>mid)
maxx=max(query(L,R,mid+,r,id<<|),maxx);
return maxx;
} }
void update(int pos,int e,int l,int r,int id)
{
if(l==r)
{
num[id]=e;
}
else
{
int mid=(l+r)>>;
if(pos<=mid)
update(pos,e,l,mid,id<<);
else if(pos>mid)
update(pos,e,mid+,r,id<<|);
num[id]=max(num[id<<],num[id<<|]);
}
}
int main()
{
int t,n,cas,i,x,y;
char ch[]; while(~scanf("%d %d",&n,&t))
{
buildtree(,n,);
while(t--)
{
scanf("%s %d %d",ch,&x,&y);
if(ch[]=='U')
{
update(x,y,,n,);
}
else
{
printf("%d\n",query(x,y,,n,) );
}
} }
return ;
}
HDU 1754的更多相关文章
- hdu 1754 Ihate it
I Hate It Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit St ...
- hdu 1754 I Hate It (splay tree伸展树)
hdu 1754 I Hate It 其实我只是来存一下我的splay模板的..请大牛们多多指教 #include<stdio.h> #include<string.h> #i ...
- hdu 1754 线段树(Max+单点修改)
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- hdu 1754 I Hate It (线段树功能:单点更新和区间最值)
版权声明:本文为博主原创文章.未经博主同意不得转载.vasttian https://blog.csdn.net/u012860063/article/details/32982923 转载请注明出处 ...
- HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值)
HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值) 点我挑战题目 题意分析 从题目中可以看出是大数据的输入,和大量询问.基本操作有: 1.Q(i,j)代表求区间max(a ...
- HDU 1754——I Hate It——————【线段树单点替换、区间求最大值】
I Hate It Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit St ...
- 线段树(单点更新) HDU 1754 I Hate It
题目传送门 /* 线段树基本功能:区间最大值,修改某个值 */ #include <cstdio> #include <cstring> #include <algori ...
- hdu 1754 I Hate It 线段树 点改动
// hdu 1754 I Hate It 线段树 点改动 // // 不多说,裸的点改动 // // 继续练 #include <algorithm> #include <bits ...
- hdu 1754 I Hate It (模板线段树)
http://acm.hdu.edu.cn/showproblem.php?pid=1754 I Hate It Time Limit: 9000/3000 MS (Java/Others) M ...
- hdu 1754 线段树模板题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754 #include <cstdio> #include <cmath> # ...
随机推荐
- C#:通过Window API接口实现WiFi
1.获取Mac地址 //WiFi通知回调 private WlanApi.WLAN_NOTIFICATION_CALLBACK _notificationCallback; this._notific ...
- 不定参数的传递VA_LIST的用法
VA_LIST的用法:(1)首先在函数里定义一具VA_LIST型的变量,这个变量是指向参数的指针: (2)然后用VA_START宏初始化变量刚定义的VA_LIST变量,使其指向第一个可 变参数的地址: ...
- C++中的类型重定义
发现重复定义是由于从两个不同的路径包含了同一个头文件而引起的,同事也建议从另外一个路径打开工程试试, 这才慢慢发现了原因.这个原因可能有些拗口,而事实上要出现这种错误也有些"曲折" ...
- bootstrap弹出层效果
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content ...
- MultiSelectComboBox(二)
1. MainWindow.xaml <Window x:Class="MultiSelectDemo.MainWindow" xmlns="htt ...
- 20150604_Andriod 窗体PopupWindow动画
参考地址: http://www.open-open.com/lib/view/open1378720752084.html http://www.jcodecraeer.com/a/anzhuoka ...
- Codeforces Round #337 Alphabet Permutations
E. Alphabet Permutations time limit per test: 1 second memory limit per test: 512 megabytes input: ...
- poj3342 Party at Hali-Bula
树形dp题,状态转移方程应该很好推,但一定要细心. http://poj.org/problem?id=3342 #include <cstdio> #include <cstrin ...
- css基本样式总结
1:背景(background) <!DOCTYPE html> <html> <head lang="en"> <meta charse ...
- WPFの exit()和close()两个方法的用法
Application.Exit 方法 通知所有消息泵必须终止,并且在处理了消息以后关闭所有应用程序窗口. Form.Close 方法 关闭窗体. 如果该窗体是应用程序的主启动窗体,则 ...