I Hate It

# 题目链接

http://acm.hdu.edu.cn/showproblem.php?pid=1754

# AC代码

```#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long

using namespace std;
const int N=2e5+10;
const int inf=0x3f3f3f3f;

int n,m,stu[N],tree[N<<2],a,b;
char op;

void Build(int l,int r,int i)
{
if(l==r)
{
tree[i]=stu[l];
return ;
}
int mid=(l+r)>>1;
Build(l,mid,i<<1);
Build(mid+1,r,i<<1|1);
tree[i]=max(tree[i<<1],tree[i<<1|1]);
return ;
}
void Update(int l,int r,int i,int x,int y)
{
if(l==r)
{
tree[i]=y;
return ;
}
int mid=(l+r)>>1;
if(x>mid) Update(mid+1,r,i<<1|1,x,y);//right subtree
else Update(l,mid,i<<1,x,y);//left subtree
tree[i]=max(tree[i<<1],tree[i<<1|1]);
return ;
}
int Query(int l,int r,int i,int x,int y)
{
int res=-inf;
if(x<=l && r<=y)
return tree[i];
if(x>r || y<l) return 0;
int mid=(l+r)>>1;
if(x<=mid) res=max(res,Query(l,mid,i<<1,x,y));//left subtree
if(y>mid) res=max(res,Query(mid+1,r,i<<1|1,x,y));//right subtree
return res;
}

int main()
{
while(~scanf("%d%d",&n,&m))
{
memset(tree,0,sizeof tree);
for(int i=1;i<=n;i++)
scanf("%d",&stu[i]);
Build(1,n,1);
while(m--)
{
cin>>op>>a>>b;
if(op=='Q')
printf("%d\n",Query(1,n,1,a,b));
else
Update(1,n,1,a,b);
}
}
return 0;
}```

02-01 14:32

2022-12-16 02:48

2022-12-30 13:52

2022-12-08 11:32

2022-12-08 16:11

2022-12-14 16:44

2022-12-11 21:41

2022-12-15 20:08

2022-12-13 21:25

2022-12-15 18:06

1 收藏 评论