AC代码:
#include <stdio.h>
#include <stdlib.h>
#define maxn 9000000
#define max(xx,yy) xx>yy?xx:yy
#define min(xx,yy) xx<yy?xx:yy
struct node
{
int l,r;
int high;
}tree[maxn];
int a[maxn],MAX;
int aa,bb;
void built( int s,int e,int n)
{
tree[n].l=s,tree[n].r=e;
if(s==e){tree[n].high=a[s];return;}
int mid=(s+e)>>1;
built(s,mid,2*n);
built(mid+1,e,2*n+1);
tree[n].high=max(tree[2*n].high,tree[2*n+1].high);
}
void query( int s,int e,int n)
{
if(tree[n].l==s&&tree[n].r==e)
{
MAX=max(MAX,tree[n].high);
}
else
{
int mid=(tree[n].l+tree[n].r)>>1;
if(s<=mid) query(s,min(mid,e),2*n);
if(e>mid) query(max(mid+1,s),e,2*n+1);
}
return ;
}
void modify( int s,int e,int n)
{
if(s==e) {tree[n].high=bb;return;}
int mid=(s+e)>>1;
if(aa<=mid)
{modify(s,mid,n*2);}
else if(aa>mid){modify(mid+1,e,n*2+1);}
tree[n].high=max(tree[2*n].high,tree[2*n+1].high);
}
int main( )
{
int N,M;
int n,x,y,i;
char s[2];
while(scanf("%d%d",&N,&M)!=EOF)
{
for( i=1;i<=N;i++)
{
scanf("%d",&a[i]);
}
built(1,N,1);
while(M--)
{
scanf("%s%d%d",s,&aa,&bb);
if(s[0]=='Q')
{
MAX=0;
query(aa,bb,1);
printf("%d\n",MAX);
}
if(s[0]=='U')
{
modify(1,N,1);
}
}
}
//system("pause");
return 0;
}