题目大意:中文题意,自行参考hdu原题
解题思路:线段树,点修改。
ac代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int maxn=2*1e5+1000;
int maxv[maxn<<2],n,m;
int a[maxn];
char q[2];
int ql,qr,p,v;
void build(int o,int L,int R)
{
int M=L+(R-L)/2;
if(L==R) maxv[o]=a[L];
else
{
build(o*2,L,M);
build(o*2+1,M+1,R);
maxv[o]=max(maxv[o*2],maxv[o*2+1]);
}
// cout<<L<<" "<<R<<" "<<o<<" "<<maxv[o]<<endl;
}
void update(int o,int L,int R)
{
int M=L+(R-L)/2;
if(L==R) maxv[o]=v;
else
{
if(p<=M) update(o*2 ,L ,M);
else update(o*2+1,M+1,R);
maxv[o]=max(maxv[o*2],maxv[o*2+1]);
}
}
int query(int o,int L,int R)
{
int M=L+(R-L)/2,ans=-1;
if(ql<=L&&R<=qr) return maxv[o];
if(ql<=M) ans=max(ans,query(o*2,L,M));
if(M<qr) ans=max(ans,query(o*2+1,M+1,R));
return ans;
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
build(1,1,n);
while(m--)
{
scanf("%s",&q);
if(q[0]=='Q')
{
scanf("%d%d",&ql,&qr);
printf("%d\n",query(1,1,n));
}
else if(q[0]=='U')
{
scanf("%d%d",&p,&v);
a[p]=v;
update(1,1,n);
}
}
}
return 0;
}