线段树的单点更新
详情请见代码:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#define maxn 200100
using namespace std;
int sto[maxn<<2];
int up[maxn<<2];
void Insert(int left,int right,int o)
{
up[o]=0;
if(left==right)
{
scanf("%d",&sto[o]);
return ;
}
int lso=o<<1;
int mid=(left+right)>>1;
Insert(left,mid,lso);
Insert(mid+1,right,lso|1);
sto[o]=max(sto[lso],sto[lso|1]);
}
void changedata(int o)
{
if(up[0]!=0)
{
int lso=o<<1;
up[lso]=up[o];
up[lso|1]=up[o];
sto[lso]=up[o];
sto[lso|1]=up[o];
up[o]=0;
}
}
int getdata(int left,int right,int o,int begin,int end,int val)
{
if(begin<=left&&right<=end)
{
if(val!=1<<28)
{
up[o]=val;
sto[o]=val;
}
return sto[o];
}
changedata(o);
int lso=o<<1;
int mid=(right+left)>>1;
int ans=-1<<10;
if(begin<=mid)ans=max(ans,getdata(left,mid,lso,begin,end,val));
if(mid<end)ans=max(ans,getdata(mid+1,right,lso|1,begin,end,val));
sto[o]=max(sto[lso],sto[lso|1]);
return ans;
}
int main()
{
int m,n;
while(~scanf("%d%d",&n,&m))
{
Insert(1,n,1);
char str[5];
int x,y;
for(int i=0;i<m;i++)
{
scanf("%s",str);
if(str[0]=='Q')
{
scanf("%d%d",&x,&y);
printf("%d\n",getdata(1,n,1,x,y,1<<28));
}
if(str[0]=='U')
{
scanf("%d%d",&x,&y);
int z=getdata(1,n,1,x,x,y);
}
}
}
return 0;
}