维护mx,编写push_up
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int mod = 998244353;
//#define int long long
typedef long long ll;
#define endl '\n'
#define mx(x) t[x].mx
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
struct SegmentTree {
int mx;
}t[N<<2];
int a[N];
void push_up(int p) {
mx(p) = max(mx(ls(p)),mx(rs(p)));
}
void build(int p,int l,int r) {
if(l == r) {
mx(p) = a[l];
return ;
}
int mid = (l + r) >> 1;
build(ls(p),l,mid); build(rs(p),mid+1,r);
push_up(p);
}
void update(int p,int l,int r,int pos,int v) {
if(l == r) {
mx(p) = v;
return ;
}
int mid = (l + r) >> 1;
if(pos <= mid) update(ls(p),l,mid,pos,v);
else update(rs(p),mid+1,r,pos,v);
push_up(p);
}
int query(int p,int l,int r,int ql,int qr) {
if(ql <= l && qr >= r) return mx(p);
int mid = (l + r) >> 1;
int res = 0;
if(ql <= mid) res = max(res,query(ls(p),l,mid,ql,qr));
if(qr > mid) res = max(res,query(rs(p),mid+1,r,ql,qr));
return res;
}
signed main(){
IOS
#ifdef ddgo
freopen("C:\\Users\\asus\\Desktop\\ddgoin.txt","r",stdin);
#endif
int n,m;
while(cin>>n>>m) {
for(int i=1;i<=n;i++) cin>>a[i];
build(1,1,n);
while(m --) {
string op; int l,r; cin>>op>>l>>r;
if(op == "U") update(1,1,n,l,r);
else cout<<query(1,1,n,l,r)<<endl;
}
}
return 0;
}