Submission #1197715

#TimeUsernameProblemLanguageResultExecution timeMemory
1197715rhombusFoehn Phenomena (JOI17_foehn_phenomena)C++20
100 / 100
74 ms5772 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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