Submission #51517

#TimeUsernameProblemLanguageResultExecution timeMemory
51517gaming0dFoehn Phenomena (JOI17_foehn_phenomena)C++11
100 / 100
178 ms5948 KiB
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int   N = 2e5 + 5;

int n, q, s, t;
int l, r, x, res = 0;
int a[N];

void solve(int l, int r, int x)
{
    int val = 0;
    if (l > 0) {
        val -= a[l-1] * (a[l-1] < 0 ? s : t);
        a[l-1] -= x;
        val += a[l-1] * (a[l-1] < 0 ? s : t);
    }
    if (r < n){
        val -= a[r] * (a[r] < 0 ? s : t);
        a[r] += x;
        val += a[r] * (a[r] < 0 ? s : t);
    }
    res += val;

    cout << res << "\n";
    return;
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> n >> q >> s >> t;
    int prev, nex; cin >> prev;
    for (int i = 0;i < n;++i) {
        cin >> nex;
        a[i] = prev - nex;
        res += (a[i] * (a[i] < 0 ? s : t));
        prev = nex;
    }

    for (int i = 0;i < q;++i) {
        cin >> l >> r >> x;
        solve(l, r, x);
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...