#include<bits/stdc++.h>
using namespace std;
#define maxn 200000
int b[maxn],v[maxn];
int n,m;
inline int lowbit(int x)
{
return x&(-x);
}
void add(int x,int val)
{
v[x]=val;
while (x<=n)
{
b[x]=max(b[x],val);
x+=lowbit(x);
}
}
int query(int x,int y)
{
int ans=v[y];
while (x<y)
{
for (y-=1;y-lowbit(y)>=x;y-=lowbit(y))
ans=max(ans,b[y]);
ans=max(ans,v[y]);
}
return ans;
}
int main(){
while (~scanf("%d%d",&n,&m))
{
memset(b,0,sizeof(b));
memset(v,0,sizeof(v));
for (int i=1;i<=n;i++)
{ int xx;
scanf("%d",&xx);
add(i,xx);
}
char s[10];int x,y;
for (int i=1;i<=m;i++)
{
scanf("%s%d%d",s,&x,&y);
if (s[0]=='Q')
printf("%d\n",query(x,y));
else if (s[0]=='U')
add(x,y);
}
}
return 0;
}
I hate it(单点修改,区间查询)
最新推荐文章于 2024-08-17 13:57:50 发布