//问最大值
//Q a b 询问[a,b]中最大值
//C a b 将a点值改为b
#include
using namespace std;
#pragma warning(disable:4996)
#define maxn 100005
#define ll long long
ll chushi[maxn], sum[maxn * 4];//记得开4倍空间
void pushup(int rt)
{
sum[rt] = max(sum[2 * rt], sum[2 * rt + 1]);
}
void build(int l, int r, int rt)
{
if (l == r)//叶节点赋值
{
sum[rt] = chushi[l];
return;
}
int mid = (l + r) / 2;//递归建树——左子树,右子树
build(l, mid, 2 * rt);
build(mid + 1, r, 2 * rt + 1);
pushup(rt);//更新父亲节点的值
}
int qurry(int x, int y, int l, int r, int rt)
{
//如果这个区间被完全包括在目标区间里面,直接返回这个区间的值
if (x <= l && y >= r)
{
return sum[rt];
}
//pushdown(rt, r - l + 1);
int mid = (l + r) / 2;
int ret = 0;
int ret1 = 0;
//cout << l << " " << r << " " << mid << endl;
if (x <= mid) ret = max(ret, qurry(x, y, l, mid, 2 * rt));//如果这个区间的左儿子和目标区间有交集那么搜索左儿子
if (y > mid) ret1 = max(ret1, qurry(x, y, mid + 1, r, 2 * rt + 1));//如果这个区间的右儿子和目标区间有交集那么搜索右儿子
return max(ret1, ret);
}
void update(int x, int c, int l, int r, int rt)
{
if (l == r)
{
sum[rt] = c;
return;
}
int mid = (l + r) / 2;
if (x <= mid)update(x, c, l, mid, 2 * rt);
else update(x, c, mid + 1, r, 2 * rt + 1);
pushup(rt);
}
int main()
{
int n, q;
cin >> n >> q;
for (int i = 1; i <= n; i++)scanf("%lld", &chushi[i]);
build(1, n, 1);
while (q--)
{
char ch;
ll a, b;
scanf(" %c%lld %lld", &ch, &a, &b);
if(ch=='Q')
printf("%d\n", qurry(a, b, 1, n, 1));
else
update(a, b, 1, n, 1);
}
}