update:单点替换 query:区间最值
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <numeric>
#include <cctype>
#include <algorithm>
#include <cmath>
#include <vector>
#include <climits>
using namespace std; const int maxn = 2e5 + ;
int maxv[maxn * ]; void update (int p, int v, int o, int L, int R) {
int M = L + ((R - L) >> );
if (L == R) {
maxv[o] = v;
} else {
if (p <= M) {
update (p, v, o << , L, M);
} else {
update (p, v, (o << ) | , M + , R);
}
maxv[o] = max (maxv[o * ], maxv[o << | ]);
}
} int query (int ql, int qr, int o, int L, int R) {
int M = L + (R - L) / , ans = INT_MIN;
if (ql <= L && R <= qr) {
return maxv[o];
}
if (ql <= M) {
ans = max (ans, query (ql, qr, o << , L, M));
}
if (M < qr) {
ans = max (ans, query (ql, qr, o << | , M + , R));
}
return ans;
} int main () {
int n, ask_n, x, a, b;
char op[];
while (~scanf ("%d%d", &n, &ask_n)) {
memset (maxv, , sizeof(maxv));
for (int i = ; i <= n; ++ i) {
scanf ("%d", &x);
update (i, x, , , n);
} while (ask_n --) {
scanf ("%s %d %d", op, &a, &b); if (op[] == 'Q') {
printf ("%d\n", query (a, b, , , n));
} else if (op[] == 'U') {
update (a, b, , , n);
}
}
}
return ;
}