#include<bits/stdc++.h>
#define ll long long
#define int long long
#define maxn 500005
#define fi first
#define se second
#define sti string
using namespace std;
ll n,a[maxn],q,S,T;
ll calc(ll Diff){
if(Diff>0) return -S*Diff;
else return -T*Diff;
}
ll diff[maxn];
signed main ()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>q>>S>>T;
for(int i=0;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++) diff[i]=a[i]-a[i-1];
ll res=0;
for(int i=1;i<=n;i++) res+=calc(diff[i]);
while(q--){
int L,R,x;
cin>>L>>R>>x;
if(L>=1 && L<=n){
res-=calc(diff[L]);
diff[L]+=x;
res+=calc(diff[L]);
}
R++;
if(R>=1 && R<=n){
res-=calc(diff[R]);
diff[R]-=x;
res+=calc(diff[R]);
}
cout<<res<<'\n';
}
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |