// ConsoleApplication12.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
// ConsoleApplication12.cpp : 定义控制台应用程序的入口点。
//
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int N;//学生数量
int M;//测试数据
while(cin >> N >> M){
vector<char> vecOp;//操作
vector<int> numA;
vector<int> numB;//输入的数据
vector<int> scores;
for (int i = 0;i < N;++i)
{
int num;
cin >> num;
scores.push_back(num);
}
while (M != 0)
{
char op;
int a, b;
cin >> op >> a >> b;
vecOp.push_back(op);
if (op == 'Q')
{
numA.push_back(a - 1);
numB.push_back(b - 1);
}
else {
numA.push_back(a - 1);
numB.push_back(b);
}
--M;
}
for (int i = 0;i < vecOp.size();++i)
{
if (vecOp[i] == 'Q')
{
int a = numA[i];
int b = numB[i];
if (a > b)
{
int temp = a;
a = b;
b = temp;
}
int max = scores[a];
for (int j = a;j <= b;++j)
{
if (max < scores[j])
{
max = scores[j];
}
}
cout << max << endl;
}
else {
scores[numA[i]] = numB[i];
}
}
}
// cout << endl;
return 0;
};