#include <bits/stdc++.h>
//#define N 200005
//#define M 599999
const int N=200005; //const比define快,
const int M=599999;
using namespace std;
struct node
{
int left,right;
int value;
}st[M]; //注意st[]和father[]这两个数组空间大概3倍(强调不是两倍)
int father[N];
int MAX;
void buildTree(int i,int left,int right) //递归,建树
{
st[i].left=left;
st[i].right=right;
st[i].value=0;
if(left==right)
{
father[left]=i;
return ;
}
buildTree(i<<1,left,(left+right)/2); //位操作比直接乘法i*2快
buildTree((i<<1)+1,(left+right)/2+1,right);
}
void updateTree(int ri) //递归,单点更新,更新ri结点的父结点
{
if(ri==1)
return ;
int fi=ri/2;
int a=st[fi<<1].value;
int b=st[(fi<<1)+1].value;
st[fi].value=(a>b)?a:b;
updateTree(fi);
}
void query(int i,int l,int r) //递归查询 ,在结点i查询[l,r]
{
if(l==st[i].left&&r==st[i].right)
{
MAX=(st[i].value>MAX)?st[i].value:MAX;
return ;
}
i=i<<1;
if(l<=st[i].right)
{
if(r<=st[i].right)
query(i,l,r);
else
query(i,l,st[i].right);
}
i=i+1;
if(r>=st[i].left)
{
if(l>=st[i].left)
query(i,l,r);
else
query(i,st[i].left,r);
}
}
int main()
{
int n,m;
while(scanf("%d %d",&n,&m)!=EOF) //本题目包含多组测试,请处理到文件结束。
{
buildTree(1,1,n);
int id=1,score;
while(n--) //输入n个学生的成绩
{
scanf("%d",&score);
st[father[id]].value=score; //底层的无条件更新成绩
updateTree(father[id]); //每一次都要更新线段树
id++;
}
char c[3];
int a,b;
while(m--) //m次查询
{
// scanf("%c",&c); //这样会读入回车,造成影响
scanf("%s",c);
if(c[0]=='Q')
{
scanf("%d %d",&a,&b);
query(1,a,b);
cout<<MAX<<endl;
MAX=-1<<20; //重新赋值为很小的初始值
}
else
{
scanf("%d %d",&a,&b);
st[father[a]].value=b;
updateTree(father[a]);
}
}
}
return 0;
}