Submission #87849

#TimeUsernameProblemLanguageResultExecution timeMemory
87849KCSCFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
749 ms168980 KiB
#include <bits/stdc++.h>
using namespace std;

const int DIM = 1000005;

long long arr[DIM], dif[DIM];

long long cost(long long val, int s, int t) {
	if (val >= 0) {
		return -val * s; }
	else {
		return -val * t; } }

int main(void) {
#ifdef HOME
	freopen("phenomena.in", "r", stdin);
	freopen("phenomena.out", "w", stdout);
#endif
	int n, q, s, t; cin >> n >> q >> s >> t;
	long long ans = 0;
	for (int i = 0; i <= n; ++i) {
		cin >> arr[i]; 
		if (i >= 1) {
			dif[i] = arr[i] - arr[i - 1];
			ans += cost(dif[i], s, t); } }
	while (q--) {
		int l, r, x;
		cin >> l >> r >> x;
		ans -= cost(dif[l], s, t); 
		dif[l] += x; ans += cost(dif[l], s, t);
		if (r < n) {
			ans -= cost(dif[r + 1], s, t);
			dif[r + 1] -= x; ans += cost(dif[r + 1], s, t); }
		cout << ans << "\n"; }  
	return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...