简单端点更新
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
#define maxn 210000
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
int n,q;
int tree[maxn<<2];
void pushup(int rt)
{
tree[rt]=max(tree[rt<<1],tree[rt<<1|1]);
}
void build(int l,int r,int rt)
{
int m=(l+r)>>1;
if(l==r)
{
scanf("%d",&tree[rt]);
return ;
}
build(lson);
build(rson);
pushup(rt);
}
void update(int l,int r,int rt,int k,int add)
{
if(l==r)
{
tree[rt]=add;
return;
}
int m=(l+r)>>1;
if(k<=m)
{
update(lson,k,add);
}
else
{
update(rson,k,add);
}
pushup(rt);
}
int query(int l,int r,int rt,int x,int y)
{
int tmp=0,tmp2=0;
if(x<=l&&y>=r)
{
return tree[rt];
}
int m=(l+r)>>1;
if(x<=m)
{
tmp=query(lson,x,y);
}
if(y>m)
{
tmp2=query(rson,x,y);
}
return max(tmp,tmp2);
}
int main()
{
int n , m;
while (~scanf("%d%d",&n,&m))
{
build(1 , n , 1);
while (m --)
{
char op[2];
int a , b;
scanf("%s%d%d",op,&a,&b);
if (op[0] == 'Q') printf("%d\n",query( 1 , n , 1,a , b ));
else update( 1 , n , 1,a , b);
}
}
return 0;
}