Submission #251894

#TimeUsernameProblemLanguageResultExecution timeMemory
251894LifeHappen__Foehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
156 ms11768 KiB
#include <bits/stdc++.h>

using namespace std;

#define int long long

#define forinc(a, b, c) for(int a=b, _c=c; a<=_c; ++a)
#define fordec(a, b, c) for(int a=b, _c=c; a>=_c; --a)
#define forv(a, b) for(auto &a : b)
#define rep(i, n) forinc(i, 1, n)
#define repv(i, n) forinc(i, 0, n - 1)

#define ii pair<int,int>
#define fi first
#define se second
#define all(a) begin(a), end(a)
#define reset(f, x) memset(f, x, sizeof(f))
#define eb emplace_back
#define pb push_back

const int N = 3e5 + 5;
int n, q, s, t;
int a[N];

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n >> q >> s >> t;
    repv(i, n + 1) cin >> a[i];
    int ans = 0;
    function<void(int, int)> add = [&](int pos, int val) {
        if(pos == n) return;
        ans -= a[pos] * (a[pos] < 0 ? s : t);
        a[pos] += val;
        ans += a[pos] * (a[pos] < 0 ? s : t);
    };
    repv(i, n) {
        int val = a[i] - a[i + 1]; a[i] = 0;
        add(i, val);
    }
    while(q--) {
        int l, r, val; cin >> l >> r >> val;
        add(l - 1, -val); add(r, val);
        cout << ans << '\n';
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...