#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define st first
#define nd second
#define pb push_back
const int maxn = 2e5+7;
ll wysokosci[maxn];
ll roznice[maxn];
ll akt[maxn];
ll wyn = 0;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n,q,s,t;
cin>>n>>q>>s>>t;
n++;
for(int i=1;i<=n;i++){
cin>>wysokosci[i];
}
for(int i=1;i<n;i++){
roznice[i] = wysokosci[i] - wysokosci[i+1];
if(wysokosci[i] < wysokosci[i+1]){
wyn -= s*(wysokosci[i+1]-wysokosci[i]);
akt[i] = s*(wysokosci[i]-wysokosci[i+1]);
}
else{
wyn += t*(wysokosci[i]-wysokosci[i+1]);
akt[i] = t*(wysokosci[i]-wysokosci[i+1]);
}
}
ll l,r,x;
while(q--){
cin>>l>>r>>x;
l++;
r++;
if(x==0){
cout<<wyn<<"\n";
continue;
}
if(r < n){
wyn -= akt[r];
roznice[r] += x;
if(roznice[r] > 0){
akt[r] = roznice[r]*t;
}
else{
akt[r] = roznice[r]*s;
}
wyn += akt[r];
}
//lewy
l--;
wyn -= akt[l];
roznice[l] -= x;
if(roznice[l] > 0){
akt[l] = roznice[l]*t;
}
else{
akt[l] = roznice[l]*s;
}
wyn += akt[l];
cout<<wyn<<"\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... |