[codeforces]round670 D. Three Sequences

在这里插入图片描述

#include<bits/stdc++.h>
#define debug(x) cout<<#x<<" is "<<x<<endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define DBG 0
const int N = 1e5 + 5;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LLINF = (1LL<<60);
using namespace std;
typedef pair<int,int> pii;
ll n,q;
ll a[N];
ll differ[N];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
#if DBG
	freopen("input.txt","r",stdin);
#endif
	cin>>n;
	ll tot  = 0;
	
	for(int i = 1;i <= n;i++){
		cin>>a[i];
		differ[i] = a[i] - a[i - 1];
		if(differ[i] > 0 && i != 1)tot += differ[i];
	}
	ll k = (differ[1] - tot) / 2;
	cout<<max(differ[1] - k,tot + k)<<endl;
	cin>>q;
	while(q--){
		ll l,r,x;
		cin>>l>>r>>x;
		if(l == 1)differ[1] += x;
		else {
			if(x < 0){
				if(differ[l] > 0)tot -= min(differ[l],-x);
			}else{
				if(differ[l] + x >= 0)tot += min(differ[l] + x,x);
			}
			differ[l] += x;
		}
		if(r + 1 <= n){
			if(x > 0){
				if(differ[r + 1] > 0)tot -= min(differ[r + 1],x);
			}else{
				if(differ[r + 1] - x >= 0)tot += min(differ[r + 1] - x,-x);
			}
			differ[r + 1] -= x;
		}
		k = (differ[1] - tot) / 2;
		cout<<max(differ[1] - k,tot + k)<<endl;
	}
	return 0;
}
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值