# HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值)

## HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值)

### 题意分析

1.Q(i,j)代表求区间max(a[k]) k∈[i,j]；
2.U(i,j)代表a[i] = j;

### 代码总览

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define nmax 200005
using namespace std;
void pushup(int rt)
{
sum[rt] = max(sum[rt<<1] ,sum[rt<<1|1]);
}
void pushdown(int rt, int ln, int rn)
{
}

}
void build(int l ,int r, int rt)
{
if(l == r){
sum[rt] = a[l];
return;
}
int m = (l+r)>>1;
build(l,m,rt<<1);
build(m+1,r,rt<<1|1);
pushup(rt);
}
void updatep(int L, int c, int l, int r, int rt)
{
if(l == r){
sum[rt] = c;
return;
}
int m = (l+r)>>1;
pushdown(rt,m-l+1,r-m);
if(L<=m) updatep(L,c,l,m,rt<<1);
else updatep(L,c,m+1,r,rt<<1|1);
pushup(rt);
}
void updatei(int L, int R, int c, int l, int r, int rt)
{
if( l>=L && r<= R){
sum[rt]+=c*(r-l+1);
return;
}
int m = (l+r)>>1;
pushdown(rt,m-l+1,r-m);
if(L<=m) updatei(L,R,c,l,m,rt<<1);
if(R>m) updatei(L,R,c,m+1,r,rt<<1);
pushup(rt);
}
int query(int L, int R, int l ,int r, int rt)
{
if(L<=l && r<=R){
return sum[rt];
}
int m = (l+r)>>1;
pushdown(rt,m-l+1,r-m);
int ANS =0;
if(L<=m) ANS = max( query(L,R,l,m,rt<<1),ANS);
if(R>m) ANS = max(query(L,R,m+1,r,rt<<1|1),ANS);
return ANS;
}
int main()
{
//freopen("in.txt","r",stdin);
int n,m;
while(scanf("%d%d",&n,&m)!= EOF){
for(int i =1;i<=n; ++i) scanf("%d",&a[i]);
build(1,n,1);
char com;
for(int i = 1;i<=m;++i){
scanf(" %c",&com);
if(com == 'Q'){
int L,R;
scanf("%d%d",&L,&R);
printf("%d\n",query(L,R,1,n,1));
}else{
int L,c;
scanf("%d%d",&L,&c);
updatep(L,c,1,n,1);
}
}
}
return 0;
}