Spoj 1716 Can you answer these queries III

和Spoj 1716 Can you answer these queries I一个题意

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long LL;
const LL INF = 0x3f3f3f3f3f3f3f3fll;
const int maxn = 50000+10;
#define Now int now,int l,int r
#define Mid int mid = (l+r)>>1
#define lson now<<1,l,mid
#define rson now<<1|1,mid+1,r
#define root 1,1,N
int N,M;

struct Info{
	LL Data_lmax,Data_rmax,Data_max,Data_sum;
	void maintain(LL x){
		Data_lmax = Data_rmax = Data_max = Data_sum = x;
	}
	Info(){
		maintain(-INF);
		Data_sum = 0;
	}
};

Info operator + (const Info & a,const Info & b){
	Info ret;
	ret.Data_sum = a.Data_sum+b.Data_sum;
	ret.Data_lmax = max(a.Data_lmax,a.Data_sum+b.Data_lmax);
	ret.Data_rmax = max(b.Data_rmax,a.Data_rmax+b.Data_sum);
	ret.Data_max = max(max(a.Data_max,b.Data_max),a.Data_rmax+b.Data_lmax);
	return ret;
}

Info Nodes[maxn<<2];
 void update(Now,int pos,LL val){
 	if(l == r){
 		Nodes[now].maintain(val);
 		return;
 	}
 	Mid;
 	if(pos <= mid)
 		update(lson,pos,val);
 	else
 		update(rson,pos,val);
 	Nodes[now] = Nodes[now<<1]+Nodes[now<<1|1];
 }

 Info query(Now,int ql,int qr){
 	if(ql <= l && r <= qr){
 		return Nodes[now];
 	}
 	Mid;
 	Info ret;
 	if(ql <= mid)
 		ret = ret + query(lson,ql,qr);
 	if(qr > mid)
 		ret = ret + query(rson,ql,qr);
 	return ret;
 }
int main(){
	int op;
	scanf("%d",&N);
	LL x;
	for(int i = 1; i <= N; i++){
		scanf("%lld",&x);
		update(root,i,x);
	}
	scanf("%d",&M);
	while(M--){
		scanf("%d",&op);
		if(op){
			int ql,qr;
			scanf("%d %d",&ql,&qr);
			printf("%lld\n",query(root,ql,qr).Data_max);
		}
		else{
			int pos;
			LL x;
			scanf("%d %lld",&pos,&x);
			update(root,pos,x);
		}
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值