Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 15716 Accepted Submission(s): 6099
//线段树基础题目2.
#include <iostream>
#include <stdio.h>
#include <string.h>
#define lson l,m,k<<1
#define rson m+1,r,k<<1|1
#define N 200000
using namespace std;
int st[N<<2];
void up(int &k)
{
st[k]=st[k<<1]>st[k<<1|1]?st[k<<1]:st[k<<1|1];
}
void build(int l,int r,int k)
{
if(l==r)
{
scanf("%d",&st[k]);
return ;
}
int m=(l+r)>>1;
build(lson);
build(rson);
up(k);
}
void updata(int &index,int &va,int l,int r,int k)
{
if(l==r)
{
st[k]=va;
return ;
}
int m=(l+r)>>1;
if(index>m) updata(index,va,rson);
else updata(index,va,lson);
up(k);
}
int query(int &L,int &R,int l,int r,int k)
{
if(L<=l&&R>=r)
{
return st[k];
}
int t1=0,t2=0,m=(l+r)>>1;
if(L<=m) t1=query(L,R,lson);
if(R>m) t2=query(L,R,rson);
return t1>t2?t1:t2;
}
int main()
{
int n,m;
char C;
int a,b;
while(scanf("%d%d",&n,&m)!=EOF)
{
build(1,n,1);
while(m--)
{
getchar();
scanf("%c",&C);
if(C=='U')
{
scanf("%d%d",&a,&b);
updata(a,b,1,n,1);
}
else
{
scanf("%d%d",&a,&b);
printf("%d\n",query(a,b,1,n,1));
}
}
}
return 0;
}