Submission #905215

#TimeUsernameProblemLanguageResultExecution timeMemory
905215andrei_iorgulescuFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
120 ms13400 KiB
#include <bits/stdc++.h>

using namespace std;

#define int long long

int n,q,s,t;
int dif[200005],a[200005];

int wind(int x)
{
    if (x > n)
        return 0;
    if (dif[x] >= 0)
        return -s * dif[x];
    else
        return t * -dif[x];
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> q >> s >> t;
    for (int i = 0; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= n; i++)
        dif[i] = a[i] - a[i - 1];
    int ans = 0;
    for (int i = 1; i <= n; i++)
        ans += wind(i);
    for (int i = 1; i <= q; i++)
    {
        int l,r,x;
        cin >> l >> r >> x;
        ans -= wind(l);
        ans -= wind(r + 1);
        dif[l] += x;
        dif[r + 1] -= x;
        ans += wind(l);
        ans += wind(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...