题目很简单就是用线段树维护区间最值。刚学删了刚才做的题重新打练习下,一遍过样例加AC哈哈
AC代码:
#include<cstdio>
#include<ctype.h>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
#include<stack>
#include<cmath>
#include<queue>
#include<set>
#include<ctime>
using namespace std;
#define pb push_back
#define ll __int64
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
int T[1<<19];
void pushup(int rt)
{
T[rt] = max(T[rt<<1],T[(rt<<1)+1]);
}
void build(int l, int r, int rt)
{
if(l == r)
{
scanf("%d",&T[rt]);
return;
}
int m = (l+r)>>1;
build(lson);
build(rson);
pushup(rt);
}
void update(int p, int k, int l, int r, int rt)
{
if(l == r)
{
T[rt] = k;
return;
}
int m = (l+r)>>1;
if(p <= m) update(p,k,lson);
else update(p,k,rson);
pushup(rt);
}
int query(int L, int R, int l, int r, int rt)
{
if(L <= l && R >= r)
return T[rt];
int m = (l+r)>>1;
int ret = 0;
if(L <= m) ret = max(ret,query(L,R,lson));
if(R > m) ret = max(ret,query(L,R,rson));
return ret;
}
int main()
{
//freopen("input.txt","r",stdin);
//freopen("o1.txt","w",stdout);
int n,m;
while(~scanf("%d%d",&n,&m))
{
build(1,n,1);
char temp;
while(m--)
{
getchar();
int a,b;
scanf("%c%d%d",&temp,&a,&b);
if(temp == 'Q') printf("%d\n",query(a,b,1,n,1));
if(temp == 'U') update(a,b,1,n,1);
}
}
return 0;
}