Submission #1013593

#TimeUsernameProblemLanguageResultExecution timeMemory
1013593vako_pFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
88 ms13136 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

const int mxN = 1e6 + 5;
ll n,q,s,t,a[mxN],b[mxN];
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll ans = 0;
	cin >> n >> q >> s >> t;
	s *= -1;
	for(int i = 0; i <= n; i++){
		cin >> a[i];
		if(i){
			b[i] = a[i - 1] - a[i];
			ans += ((b[i] < 0) ? s : t) * abs(b[i]);
		} 
	}
	while(q--){
		ll x,l,r;
		cin >> l >> r >> x;
		if(l != 0){
			ans -= ((b[l] < 0) ? s : t) * abs(b[l]);
			b[l] -= x;
			ans += ((b[l] < 0) ? s : t) * abs(b[l]);
		}
		if(r != n){
			ans -= ((b[r + 1] < 0) ? s : t) * abs(b[r + 1]);
			b[r + 1] += x;
			ans += ((b[r + 1] < 0) ? s : t) * abs(b[r + 1]);
		}
		cout << ans << '\n';
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...