#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
const int maxn=500004;
int number[maxn];
int ans=-100;
struct node
{
int l,r,big;
};
node a[1000000];
void update(int k)
{
a[k].big=max(a[k*2].big,a[k*2+1].big);
}
void build(int k,int l,int r)
{
a[k].l=l,a[k].r=r;
if(l==r)
{
a[k].big=number[l];
return ;
}
int mid=(l+r)/2;
build(k*2,l,mid);
build(k*2+1,mid+1,r);
update(k);
}
void query(int k,int ll,int rr)
{
int mid=(a[k].r+a[k].l)/2;
if(a[k].r<=rr&&a[k].l>=ll)
{
ans=max(ans,a[k].big);
return;
}
if(ll<=mid)
{
query(2*k,ll,rr);
}
if(rr>mid)
{
query(2*k+1,ll,rr);
}
}
void changepoint(int k,int x,int y)
{
int mid=(a[k].l+a[k].r)/2;
if(a[k].l==a[k].r)
{
a[k].big=y;
return;
}
if(x<=mid)
changepoint(k*2,x,y);
else
{
changepoint(k*2+1,x,y);
}
update(k);
}
int main()
{
int n,m;
while(cin>>n>>m){
ans=-100;
for(int i=1; i<=n; i++)
{
scanf("%d",&number[i]);
}
build(1,1,n);
while(m--)
{
char l;
int q,w;
cin>>l>>q>>w;
if(l=='Q')
{
ans=-100;
query(1,q,w);
cout<<ans<<endl;
}
else
{
changepoint(1,q,w);
}
}}
}
08-31
166
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-03
07-02
07-22
07-22