//fast
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(n) for(int i = 0 ; i<n ; i++)
#define all(x) x.begin(),x.end()
#define pb push_back
ll s,t,n;
const int base = 2e5+7;
ll alt[base];
ll diff[base];
ll update(int a, int b){
ll w = 0;
if (diff[a-1]<0){
w+=diff[a-1]*s;
}else w+=diff[a-1]*t;
if (b!=n){
if (diff[b]<0){
w+=diff[b]*s;
}else w+=diff[b]*t;
}
return w;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int q;
cin >> n >> q >> s >> t;
ll sum = 0;
cin >> alt[0];
rep(n){
cin >> alt[i+1];
if (alt[i]>alt[i+1]){
sum+=(alt[i]-alt[i+1])*t;
}else sum+=(alt[i]-alt[i+1])*s;
diff[i] = alt[i]-alt[i+1];
}
while (q--){
int l,r,x;
cin >> l >> r >> x;
sum-=update(l,r);
diff[l-1]-=x;
diff[r]+=x;
sum+=update(l,r);
cout << sum << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |