제출 #1150841

#제출 시각아이디문제언어결과실행 시간메모리
1150841pinbuFoehn Phenomena (JOI17_foehn_phenomena)C++20
100 / 100
61 ms6572 KiB
#include <bits/stdc++.h>
using namespace std;

const int N = 200005;
const long long oo = 1e18;

int n, q, s, t, a[N]; long long d[N];
void solve(void) {
	cin >> n >> q >> s >> t;
	long long ans = 0;
	cin >> a[0];
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		d[i] = a[i - 1] - a[i];
		ans += 1LL * d[i] * (d[i] < 0 ? s : t);
	}
	auto update = [&] (int i, int x) {
		ans -= 1LL * d[i] * (d[i] < 0 ? s : t);
		d[i] += x;
		ans += 1LL * d[i] * (d[i] < 0 ? s : t);
	};
	while (q--) {
		int l, r, x; cin >> l >> r >> x;
		update(l, -x);
		if (r < n) update(r + 1, +x);
		cout << ans << '\n';
	}
}

signed main(void) {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    
    int T = 1;// cin >> T; 
    while (T--) solve();
    
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...