# I Hate It

Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 13403 Accepted Submission(s): 5188

Problem Description

Input

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
AC代码：
#include<iostream>
#include<string.h>
#include<algorithm>
#define N 200001
#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define M(x,y) ((x+y)>>1)
using namespace std;
int maxx=-0xfffff;
typedef struct str
{
int l;
int r;
int key;
}Node;
Node node[4*N];
int value[N];
int bulid(int t,int l,int r)
{
node[t].l=l;
node[t].r=r;
if(l==r-1) return node[t].key=value[r];
int mid=M(l,r);
return node[t].key=max( bulid(L(t),l,mid),bulid(R(t),mid,r));
}
void update(int t,int l,int sum)
{
if(node[t].l==node[t].r-1)
{
node[t].key=sum;
return;
}
int mid=M(node[t].l,node[t].r);
if(l>=mid) update(R(t),l,sum);
else       update(L(t),l,sum);
node[t].key=max(node[L(t)].key,node[R(t)].key);
}
int Quary(int t,int l,int r)
{
if(node[t].l==l&&node[t].r==r)  return node[t].key;
int mid=M(node[t].l,node[t].r);
if(l>=mid) return Quary(R(t),l,r);
else
{
if(r<=mid) return Quary(L(t),l,r);
else  return max(Quary(R(t),mid,r), Quary(L(t),l,mid));
}
}
int main()
{
int n,m;
while(cin>>n>>m)
{

for(int i=1;i<=n;++i)
cin>>value[i];
bulid(1,0,n);
char ch;
for(int i=0;i<m;++i)
{
cin>>ch;
int x,y;
cin>>x>>y;
if(ch=='Q') cout<<Quary(1,x-1,y)<<endl;
else update(1,x-1,y);
}
}return 0;
}

#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
typedef struct NODE
{
int ld;
int rd;
struct NODE *lc,*rc;
int key;
NODE()
{
rc=lc=NULL;

}
}*Node,T;
int value[200001];
Node build(int a,int b)
{
Node p=new T;
p->ld=a;
p->rd=b;
if(a==b-1)
{
p->key=value[b];
return p;
}
int mid=(a+b)/2;
p->rc=build(mid,b);
p->lc=build(a,mid);
p->key=max(p->rc->key,p->lc->key);
return p;
}
void update(Node p,int a,int b)
{
if(p->ld==p->rd-1)
{
p->key=b;
return ;
}
int mid=(p->ld+p->rd)/2;
if(a>=mid) update(p->rc,a,b);
else update(p->lc,a,b);
p->key=max(p->lc->key,p->rc->key);
}
int  Quary(Node p,int a,int b)
{
if(p->ld==a&&p->rd==b) return p->key;
int mid=(p->ld+p->rd)/2;
if(a>=mid) return Quary(p->rc,a,b);
else
{
if(b<=mid) return Quary(p->lc,a,b);
else return max(Quary(p->rc,mid,b),Quary(p->lc,a,mid));
}
}
void delet(Node p)//后序遍历删结点
{
if(p->lc) delet(p->lc);
if(p->rc) delet(p->rc);
delete p;
}
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
for(int i=1;i<=n;++i)
scanf("%d",&value[i]);
Node p=new T;
p=build(0,n);
for(int i=0;i!=m;++i)
{    getchar();
char ch;
int x,y;
scanf("%c%d%d",&ch,&x,&y);
if(ch=='Q')  printf("%d\n",Quary(p,x-1,y));
else  update(p,x-1,y);
}
delet(p);
}

return 0;
}

#### hdu - 1576 - A/B（乘法逆元）

2014-11-03 13:07:08

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

2012-02-27 19:51:20

#### Red and Black&&http://acm.hdu.edu.cn/showproblem.php?pid=1312

2012-07-25 13:17:27

#### Robberies&&http://acm.hdu.edu.cn/showproblem.php?pid=2955

2012-01-10 09:46:54

#### HDU-1274-展开字符串（dfs分段字符串处理）

2017-03-04 13:41:00

#### POJ2255 HDU1710【树的遍历】【水题】

2017-03-28 19:31:04

#### HDU 2141 Can you find it? 二分查找

2015-07-29 19:35:01

#### HDU 2866 Special Prime 找规律

2016-03-18 18:55:21

#### 题解： HDU 2141 Can you find it? （二分查找）

2015-12-06 19:03:48

#### HDU 1083 二分匹配

2012-09-24 15:54:03

## 不良信息举报

http://acm.hdu.edu.cn/showproblem.php?pid=1754&&线段树区间求最值