#include "stdio.h"
#include "string.h"
#include "algorithm"
using namespace std;
const int maxn = 200005;
const int inf = 1<<30;
int n,m;
int x,y,ad,ans;
int tree[maxn*3];
int c[maxn];
void PushUp( int t )
{
tree[t]= tree[t<<1] >= tree[t<<1|1]?tree[t<<1] : tree[t<<1|1];
}
void buildtree( int ld,int rd,int t )
{
if( ld == rd )
{
tree[t] = c[ld];
return;
}
int mid = ( ld + rd )>>1;
buildtree( ld,mid,t<<1 );
buildtree( mid+1,rd,t<<1|1 );
PushUp(t);
}
void updata( int ld,int rd,int t )
{
if( ld == rd )
{
tree[t] = ad;
return;
}
int mid = ( ld + rd )>>1;
if( x <= mid )
updata( ld,mid,t<<1 );
else if( x > mid )
updata( mid+1,rd,t<<1|1 );
PushUp(t);
}
void query( int ld,int rd,int t )
{
if( ld >= x && rd <= y )
{
ans = ans > tree[t]?ans : tree[t];
return;
}
int mid = ( ld + rd )>>1;
if( x <= mid )
query( ld,mid,t<<1 );
if( y > mid )
query( mid+1,rd,t<<1|1 );
}
int main()
{
//freopen( "data.txt","r",stdin );
char ch[3];
while( scanf("%d%d",&n,&m) == 2 )
{
for( int i = 1; i <= n; i ++ )
{
scanf("%d",&c[i]);
}
buildtree(1,n,1);
for( int i = 1; i <= m; i ++ )
{
getchar();
scanf("%s",ch);
if( ch[0] == 'Q' )
{
scanf("%d%d",&x,&y);
ans = -inf;
query( 1,n,1 );
printf("%d\n",ans);
}
else if( ch[0] == 'U' )
{
scanf("%d%d",&x,&ad);
updata( 1,n,1 );
}
}
}
return 0;
}
HDU-1754 I Hate It 线段树
最新推荐文章于 2022-03-31 16:32:13 发布