链接:点击打开链接
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define MAXN 200005
using namespace std;
int tree[MAXN<<2];
void PushUp(int root){
tree[root]=max(tree[root<<1],tree[root<<1|1]);
}
void BuildTree(int left,int right,int root){
if(left==right){
scanf("%d",&tree[root]);
return;
}
int m=(left+right)>>1;
BuildTree(left,m,root<<1);
BuildTree(m+1,right,root<<1|1);
PushUp(root);
}
void Update(int p,int key,int left,int right,int root){
if(left==right){
tree[root]=key;
return;
}
int m=(left+right)>>1;
if(p<=m)
Update(p,key,left,m,root<<1);
else
Update(p,key,m+1,right,root<<1|1);
PushUp(root);
}
int Query(int L,int R,int left,int right,int root){
if(L<=left&&R>=right){
return tree[root];
}
int m=(left+right)>>1;
int num1=0,num2=0;
if(L<=m)
num1=Query(L,R,left,m,root<<1);
if(R>m)
num2=Query(L,R,m+1,right,root<<1|1);
return max(num1,num2);
}
int main(){
int n,m;
int num1,num2;
char op[10];
while(scanf("%d%d",&n,&m)!=EOF){
BuildTree(1,n,1);
for(int i=1;i<=m;i++){
scanf("%s%d%d",op,&num1,&num2);
switch(op[0]){
case 'Q':printf("%d\n",Query(num1,num2,1,n,1));break;
case 'U':Update(num1,num2,1,n,1);break;
}
}
}
return 0;
}