Submission #751362

#TimeUsernameProblemLanguageResultExecution timeMemory
751362vjudge1Foehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
648 ms34496 KiB
#include<bits/stdc++.h>
#define ll long long
using namespace std;

map<ll, ll> a, m;
ll n, q, s, t, l, r, x, pos, neg;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> q >> s >> t;
	s *= -1; t *= -1;
	a[0] = 0;
	for(int i=0; i<=n; i++){
		cin >> a[i];
		ll tmp = a[i] - a[i-1];
		m[i] = tmp;
		if(tmp < 0) neg += tmp;
		else pos += tmp;
	}
	for(int i=1; i<=q; i++){
		cin >> l >> r >> x;
		
		ll tmp = m[l];
		if(tmp >= 0){
			pos -= tmp;
			tmp += x;
		}
		else{
			neg -= tmp;
			tmp += x;
		}
		if(tmp > 0)	pos += tmp;
		else neg += tmp;
		
		if(r != n){
			tmp = m[r+1];
			if(tmp > 0){
				pos -= tmp;
				tmp -= x;
			}
			else{
				neg -= tmp;
				tmp -= x;
			}
			if(tmp > 0)	pos += tmp;
			else neg += tmp;
		}
		ll ans = (s*pos) + (t*neg);
		m[l] += x;
		m[r+1] -= x;
		
		cout << ans << '\n';
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...