http://acm.hdu.edu.cn/showproblem.php?pid=1754
模板。
/*1062ms,2284KB*/
#include <cstdio>
#include <algorithm>
using namespace std;
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define root 1, n, 1
const int mx = 200000;
int maxs[mx << 2];
inline void pushup(int rt)
{
maxs[rt] = max(maxs[rt << 1], maxs[rt << 1 | 1]);
}
void build(int l, int r, int rt)
{
if (l == r)
{
scanf("%d", &maxs[rt]);
return;
}
int m = (l + r) >> 1;
build(lson);
build(rson);
pushup(rt);
}
void update(int p, int s, int l, int r, int rt)
{
if (l == r)
{
maxs[rt] = s;
return;
}
int m = (l + r) >> 1;
if (p <= m) update(p, s, lson);
else update(p, s, rson);
pushup(rt);
}
int query(int ql, int qr, int l, int r, int rt)
{
if (ql <= l && r <= qr)
{
return maxs[rt];
}
int maxs = 0, m = (l + r) >> 1;
if (ql <= m) maxs = query(ql, qr, lson);
if (m < qr) maxs = max(maxs, query(ql, qr, rson));
return maxs;
}
int main()
{
int n, m, a, b;
char c;
while (~scanf("%d%d", &n, &m))
{
build(root);
while (m--)
{
getchar();
scanf("%c%d%d", &c, &a, &b);
if (c == 'U') update(a, b, root);
else printf("%d\n", query(a, b, root));
}
}
return 0;
}