Submission #1335051

#TimeUsernameProblemLanguageResultExecution timeMemory
1335051lunarechoFoehn Phenomena (JOI17_foehn_phenomena)C++20
100 / 100
70 ms7380 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, q;
    cin>>n>>q;
    ll s, t;
    cin>>s>>t;
    vector<ll> a(n + 1);
    for(auto &i : a) {
        cin>>i;
    }    
    vector<ll> d(n + 1);
    for(int i=1;i<=n;++i) {
        d[i] = a[i] - a[i - 1];
    }
    auto c = [&](ll f) -> ll {
        return f > 0 ? -s * f : -t * f;
    };
    ll ans = 0;
    for(int i=1;i<=n;++i) {
        ans += c(d[i]);
    }
    while(q--) {
        int l, r;
        ll x;
        cin>>l>>r>>x;
        ans -= c(d[l]);
        d[l] += x;
        ans += c(d[l]);
        if(r + 1 <= n) {
            ans -= c(d[r + 1]);
            d[r + 1] -= x;
            ans += c(d[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...