Submission #1258760

#TimeUsernameProblemLanguageResultExecution timeMemory
1258760bruhhhhFoehn Phenomena (JOI17_foehn_phenomena)C++20
100 / 100
62 ms7240 KiB
#include <bits/stdc++.h>
using namespace std;

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