Submission #670921

#TimeUsernameProblemLanguageResultExecution timeMemory
670921DorostFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
338 ms11292 KiB
/* 	* In the name of GOD  */

#pragma GCC optimize("O3,unroll-loops")

#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
#define F first
#define S second
#define mk make_pair
const int N = 201234;
ll a[N];
int b[N];
int n, q, s, t;

ll f(ll x) {
	if (x >= 0)
		return x * s;
	else
		return x * t;
}

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