#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[200005];
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, q, s, t; cin>>n>>q>>s>>t;
for(int i = 0; i <= n; i++) cin>>a[i];
for(int i = n; i >= 1; i--) a[i] -= a[i-1];
int ans = 0;
for(int i = 1; i <= n; i++){
if(a[i] > 0) ans -= s*a[i];
else ans -= t*a[i];
}
for(int test = 0; test < q; test++){
int l, r, x; cin>>l>>r>>x;
r++;
if(a[l] > 0) ans += s*a[l];
else ans += t*a[l];
a[l] += x;
if(a[l] > 0) ans -= s*a[l];
else ans -= t*a[l];
if(r <= n){
if(a[r] > 0) ans += s*a[r];
else ans += t*a[r];
a[r] -= x;
if(a[r] > 0) ans -= s*a[r];
else ans -= t*a[r];
}
cout<<ans<<'\n';
/*for(int i = 1; i <= n; i++) cerr<<a[i]<<" ";
cerr<<endl;*/
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |