hdu 1754 I Hate It 线段树 单点更新

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 200001
int maxn[N<<2];
int x;
void build(int l,int r,int rt){
	if(l==r){
		scanf("%d",&x);
		maxn[rt]=x;
		return;
	}
	int mid=(l+r)>>1;
	build(l,mid,rt<<1);
	build(mid+1,r,rt<<1|1);
	maxn[rt]=max(maxn[rt<<1],maxn[rt<<1|1]);
}

void update(int l,int r,int pos,int x,int rt){
	if(l==r){
		maxn[rt]=x;
		return;
	}
	int mid=(l+r)>>1;
	if(pos<=mid) update(l,mid,pos,x,rt<<1);
	else update(mid+1,r,pos,x,rt<<1|1);
	maxn[rt]=max(maxn[rt<<1],maxn[rt<<1|1]);
}

int query(int l,int r,int st,int ed,int rt){
	if(l>=st&&r<=ed){
		return maxn[rt];
	}
	int mid=(l+r)>>1;
	int temp=0;
	if(st<=mid) temp=max(temp,query(l,mid,st,ed,rt<<1));
	if(ed>mid) temp=max(temp,query(mid+1,r,st,ed,rt<<1|1));
	return temp;
}
int main(){
	int n,m;
	while(scanf("%d%d",&n,&m)!=EOF){
		build(1,n,1);
		char ch[3];
		int r,c;
		while(m--){
			scanf("%s%d%d",&ch,&r,&c);
			if(ch[0]=='U') update(1,n,r,c,1);
			else printf("%d\n",query(1,n,r,c,1));
		}
	}
	return 0;
}
裸裸的线段树。。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值