include
include <stdio.h>
include <stdlib.h>
include <math.h>
using namespace std;
const int MaxNode=524288;
const int MaxStu=200001;
struct Node{
int value;
int left,right;
}node[MaxNode];
int father[MaxStu];
void BuildTree( int i,int left,int right)
{
node[i].left=left;
node[i].right=right;
node[i].value=0;
if(right==left)
{
father[left]=i;
return;
}
BuildTree(i<<1,left,(int)floor((left+right)/2.0));
BuildTree((i<<1)+1,(int)floor((left+right)/2.0)+1,right);
}
void UpdateTree(int ri)
{
if(ri==1) return;
int fi=ri/2;
int a=node[fi<<1].value;
int b=node[(fi<<1)+1].value;
node[fi].value=(a>b)?a:b;
UpdateTree(ri/2);
}
int MAX;
void Query(int i,int l,int r)
{
if(node[i].leftl && node[i].rightr)
{
MAX=(MAX<node[i].value)?node[i].value:MAX;
return;
}
i=i<<1;
if(l<=node[i].right)
{
if(r<=node[i].right)
Query(i,l,r);
else
Query(i,l,node[i].right);
}
i=i+1;
if(r>=node[i].left)
{
if(l>=node[i].left)
Query(i,l,r);
else
Query(i,node[i].left,r);
}
}
int main()
{
int N,M,igrade;
while(scanf("%d%d",&N,&M)!=EOF){
BuildTree(1,1,N);
for(int i=1;i<=N;i++)
{
scanf("%d",&igrade);
node[father[i]].value=igrade;
UpdateTree(father[i]);
}
while(M--)
{
char ch[3];
int a,b;
scanf("%s %d %d",ch,&a,&b);
if(ch[0] == 'Q')
{
MAX=0;
Query(1,a,b);
printf("%d
",MAX);
}
else if(ch[0]=='U')
{
node[father[a]].value=b;
UpdateTree(father[a]);
}
}
}
return 0;
}