Submission #1336414

#TimeUsernameProblemLanguageResultExecution timeMemory
1336414duyanhchupapiFoehn Phenomena (JOI17_foehn_phenomena)C++20
30 / 100
64 ms4376 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 3, mod = 998244353;
int n, q, S, T, a[N];
ll ans;

ll get(int i) {
	if (i > n) return 0;
	if (a[i] > 0) return -1LL * a[i] * S;
	return -1LL * a[i] * T;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	// freopen(".inp", "r", stdin);
	// freopen(".out", "w", stdout);
	cin >> n >> q >> S >> T;
	for (int i = 0; i <= n; ++i) cin >> a[i];
	for (int i = n; i >= 1; --i) {
		a[i] -= a[i - 1];
		ans += get(i);
	}
	
	// cout << ans << '\n';
	
	while (q--) {
		int l, r, x;
		cin >> l >> r >> x;
		ans -= get(l) + get(r + 1);
		a[l] += x;
		a[r + 1] -= x;
		ans += get(l) + get(r + 1);
		cout << ans << '\n';
	}	

}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...