Submission #1258687

#TimeUsernameProblemLanguageResultExecution timeMemory
1258687quanaskingerFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
291 ms8512 KiB
#include <bits/stdc++.h>
using namespace std;
long long m, n, q, l, r, x, y, s, t;
long long change(long long x)
{
    long long hs = (x < 0 ? t : -s);
    return hs * abs(x - y);
}
int main()
{
    cin >> n >> q >> s >> t;
    long long diff[n + 5], arr[n + 5], res = 0;
    for (long long i = 0; i <= n; i++)
    {
        cin >> arr[i];
        if (i > 0)
        {
            diff[i] = arr[i] - arr[i - 1];
            res += change(diff[i]);
        }
    }
    while (q--)
    {
        cin >> l >> r >> x;
        if (l >= 1)
        {
            res -= change(diff[l]);
            res += change(diff[l] + x);
        }
        if (r < n)
        {
            res -= change(diff[r + 1]);
            res += change(diff[r + 1] - x);
        }
        diff[l] += x;
        diff[r + 1] -= x;
        cout << res << "\n";
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...