Submission #51460

#TimeUsernameProblemLanguageResultExecution timeMemory
51460EntityITFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
173 ms7536 KiB
#include<bits/stdc++.h>

using namespace std;

#define int long long

const int N = 200005;
int n, q, s, t, a[N], ans, rem[N];

void upd1 (int l) {
    if (rem[l] > 0) ans += s * rem[l];
    else ans += t * rem[l];
}

void upd2 (int l) {
    if (rem[l] > 0) ans -= s * rem[l];
    else ans -= t * rem[l];
}

signed main () {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> q >> s >> t;
    for (int i = 0; i <= n; ++i) {
        cin >> a[i];
        if (i) {
            rem[i] = a[i] - a[i - 1];
            if (a[i] > a[i - 1]) ans -= s * (a[i] - a[i - 1]);
            else ans += t * (a[i - 1] - a[i]);
        }
    }

    while (q--) {
        int l, r, _x; cin >> l >> r >> _x;
        upd1 (l);
        if (r < n) {
            upd1 (r + 1);
        }
        rem[l] += _x;
        if (r < n) {
            rem[r + 1] -= _x;
        }
        upd2 (l);
        if (r < n) {
            upd2 (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...