单点修改,区间最值。
#include <cstdio>
#include <algorithm>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int maxn=200500;
int MAX[maxn<<2];
void pushup(int rt)
{
MAX[rt]=max(MAX[rt<<1], MAX[rt<<1|1]);
}
void build(int l, int r, int rt)
{
if(l==r)
{
scanf("%d", &MAX[rt]);
return ;
}
int mid=(r+l)>>1;
build(lson);
build(rson);
pushup(rt);
}
void update(int p, int c, int l, int r, int rt)
{
if(l==r)
{
MAX[rt]=c;
return ;
}
int mid=(l+r)>>1;
if(p<=mid)update(p, c, lson);
else update(p, c, rson);
pushup(rt);
}
int query(int L, int R, int l, int r, int rt)
{
if(L<=l && R>=r)
return MAX[rt];
int mid=(l+r)>>1;
int ret=0;
if(L<=mid)ret=max(ret, query(L, R, lson));
if(R>mid)ret=max(ret, query(L, R, rson));
return ret;
}
int main()
{
// freopen("in.txt", "r", stdin);
int n, m;
while(~scanf("%d%d", &n, &m))
{
build(1, n, 1);
while(m--)
{
char op[2];
int a, b;
scanf("%s%d%d", op, &a, &b);
if(op[0]=='Q')
printf("%d\n", query(a, b, 1, n, 1));
else update(a, b, 1, n, 1);
}
}
return 0;
}
诡异的是op当作单个字符,用%c和getchar()读,都超时,用%s就能过......