线段树 单点更新
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<stack>
#include<algorithm>
#define mx 200005
#define LL long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
int ma[mx<<2];
int max(int a,int b){
if(a>b)return a;
return b;
}
void build(int l,int r,int rt){
if(l==r){
scanf("%d",&ma[rt]);
return;
}
int m=(l+r)>>1;
build(lson);
build(rson);
ma[rt]=max(ma[rt<<1],ma[rt<<1|1]);
}
void update(int a,int b,int l,int r,int rt){
if(l==r){ma[rt]=b;return;}
int m=(l+r)>>1;
if(a<=m)update(a,b,lson);
else update(a,b,rson);
ma[rt]=max(ma[rt<<1],ma[rt<<1|1]);
}
int query(int L,int R,int l,int r,int rt){
if(L<=l&&r<=R)return ma[rt];
int m=(l+r)>>1;
int ans=-1;
if(L<=m)ans=max(ans,query(L,R,lson));
if(R>m)ans=max(ans,query(L,R,rson));
return ans;
}
int main(){
int n,m;
while(scanf("%d %d",&n,&m)==2){
build(1,n,1);
char s[5];
int a,b;
while(m--){
scanf("%s %d %d",s,&a,&b);
if(s[0]=='Q'){
printf("%d\n",query(a,b,1,n,1));
}
else update(a,b,1,n,1);
}
}
return 0;
}