#include<iostream>
#include<cstdio>
using namespace std;
int a[200000+10];
struct node{
int s,t,ma;
struct node *l,*r;
node(){
ma=0;l=NULL;r=NULL;
}
};
int js(struct node *h){
struct node *p,*q;
if(h->s==h->t){
h->ma=a[h->s];return h->ma;
}
p=new node;p->s=h->s;p->t=(h->s+h->t)/2;
q=new node;q->s=(h->s+h->t)/2+1;q->t=h->t;
h->l=p;h->r=q;
int x=js(p);int y=js(q);
h->ma=max(x,y);
return h->ma;
}
int dfs(node *h,int x,int y){
if(y<h->s || x>h->t)return 0;
if(x<=h->s && y>=h->t)return h->ma;
int x1=dfs(h->l,x,y);int x2=dfs(h->r,x,y);
return max(x1,x2);
}
int up(node *h,int x){
if(h->s==h->t && h->s==x){
h->ma=a[x];return h->ma;
};
if(x<h->s || x>h->t)return h->ma;
int x1=up(h->l,x);
int x2=up(h->r,x);
h->ma=max(x1,x2);
return h->ma;
}
int main(){
int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
struct node *h;
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
h=new node;h->s=1;h->t=n;
js(h);
for(int i=1;i<=m;i++){
char c;int x,y;
getchar();
scanf("%c %d %d",&c,&x,&y);
if(c=='Q'){
printf("%d\n",dfs(h,x,y));
}
if(c=='U'){
a[x]=y;
up(h,x);
}
}
}
return 0;
}
HDU1754 动态线段树,超内存了~
最新推荐文章于 2019-02-24 21:50:32 发布