| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 51467 | combi2k2 | Foehn Phenomena (JOI17_foehn_phenomena) | C++14 | 0 ms | 0 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int   N   = 2e5 + 1;
int a[N], n, q, s, t;
int f(int x)    {
    if(x < 0)   return x * s;
    return x * t;
}
int main(){
    ios_base::sync_with_stdio(false);   cin.tie(0);
    cin >> n >> q >> s >> t;
    int ans = 0;
    for(int i = 0 ; i <= n ; ++i)   {
        cin >> a[i];
        if(i)   {
            a[i - 1] = a[i - 1] - a[i];
            ans += f(a[i - 1]);
        }
    }
    while(q--)  {
        int l, r, x;
        cin >> l >> r >> x;
        if(l > 0)   {
            ans -= f(a[l - 1]); a[l - 1] -= x;
            ans += f(a[l - 1]);
        }
        if(r < n)   {
            ans -= f(a[r]);     a[r] += x;
            ans += f(a[r]);
        }
        cout << ans << "\n";
    }
}
