제출 #129309

#제출 시각아이디문제언어결과실행 시간메모리
129309LatinaFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
152 ms6596 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

ll s, t;
ll dif[300005];

ll get(ll d) {
    if (d > 0) return -s*d;
    else return -t*d;
}

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