//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
const int base = 2e5+7;
const int tbase = (1<<18);
ll tree[tbase*2];
ll alt[base];
ll s,t,n;
void dod(int a, int b, ll x){
a+=tbase-1;
b+=tbase+1;
while (b-a>1){
if (a%2==0) tree[a+1]+=x;
if (b%2==1) tree[b-1]+=x;
a/=2;
b/=2;
}
}
int zap(int x){
ll w = alt[x];
x+=tbase;
while (x>=1){
w+=tree[x];
x/=2;
}
return w;
}
ll update(int l, int r){
ll w = 0;
if (l!=0){
ll a = zap(l-1);
ll b = zap(l);
if (a>b) w+=(a-b)*t;
else w+=(a-b)*s;
}
if (r!=n){
ll a = zap(r);
ll b = zap(r+1);
if (a>b) w+=(a-b)*t;
else w+=(a-b)*s;
}
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;
}
while (q--){
int l,r,x;
cin >> l >> r >> x;
sum-=update(l,r);
dod(l,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... |