标签:
Description
Input
Output
Sample Input
Sample Output
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<cstdlib>
using namespace std;
#define N 200010
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define INF 0x7fffffff
int n,m,sum[N<<2],maxx[N<<2],ans;
void pushup(int rt)
{
maxx[rt]=max(maxx[rt<<1],maxx[rt<<1|1]);
}
void build(int l,int r,int rt)
{
if(l==r)
{
maxx[rt]=sum[l];
return ;
}
int m=(l+r)>>1;
build(lson);
build(rson);
pushup(rt);
}
void query(int L,int R,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
ans=max(maxx[rt],ans);
return ;
}
int m=(l+r)>>1,ret=0;
if(L<=m) query(L,R,lson);
if(m<R) query(L,R,rson);
}
void add(int x,int c,int l,int r,int rt)
{
if(l==x&&r==x)
{
maxx[rt]=c;
return ;
}
int m=(l+r)>>1;
if(x<=m) add(x,c,lson);
else add(x,c,rson);
pushup(rt);
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=1;i<=n;i++)
scanf("%d",&sum[i]);
build(1,n,1);
char s[5];
int x,y;
while(m--)
{
scanf("%s",s);
scanf("%d%d",&x,&y);
if(s[0]==‘Q‘)
{
ans=0;
query(x,y,1,n,1);
printf("%d\n",ans);
}
else if(s[0]==‘U‘)
{
add(x,y,1,n,1);
}
}
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/a972290869/p/4253319.html