Submission #1143731

#TimeUsernameProblemLanguageResultExecution timeMemory
1143731NomioFoehn Phenomena (JOI17_foehn_phenomena)C++20
100 / 100
72 ms7236 KiB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int n, q;
ll s, t;
ll f(ll x) {
	if(x > 0) return x * s;
	else return x * t;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> q >> s >> t;
	ll a[n + 1];
	for(int i = 0; i <= n; i++) {
		cin >> a[i];
	}
	ll diff = 0, dif[n + 2] {};
	for(int i = 1; i <= n; i++) {
		dif[i] = a[i] - a[i - 1];
		if(a[i] >= a[i - 1]) diff += (a[i] - a[i - 1]) * -s;
		else diff += (a[i - 1] - a[i]) * t;
	}
//	cout << diff << '\n';
	while(q--) {
		int l, r;
		ll val;
		cin >> l >> r >> val;
		diff += f(dif[l]);
		dif[l] += val;
		diff -= f(dif[l]);
		r++;
		if(r <= n) {
			diff += f(dif[r]);
			dif[r] -= val;
			diff -= f(dif[r]);
		}
		cout << diff << '\n';
	}
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...