#include <bits/stdc++.h>
using namespace std;
const int sized = 200000;
long long a[sized + 5];
long long manghieu[sized + 5];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n,q,s,t;
cin >> n >> q >> s >> t;
for(int i = 0;i<=n;i++){
cin >> a[i];
}
for(int i = 1;i<=n;i++){
manghieu[i] = a[i] - a[i-1];
}
long long tong = 0;
for(int i = 1;i<=n;i++){
if(manghieu[i] <= 0) tong += abs(manghieu[i]) * t;
else tong -= abs(manghieu[i]) * s;
}
long long l,r,x;
while(q--){
cin >> l >> r >> x;
if(manghieu[l] <= 0) tong -= abs(manghieu[l]) * t;
else tong += abs(manghieu[l]) * s;
manghieu[l] += x;
if(manghieu[l] <= 0) tong += abs(manghieu[l]) * t;
else tong -= abs(manghieu[l]) * s;
if(r < n){
if(manghieu[r + 1] <= 0) tong -= abs(manghieu[r + 1]) * t;
else tong += abs(manghieu[r + 1]) * s;
manghieu[r + 1] -= x;
if(manghieu[r + 1] <= 0) tong += abs(manghieu[r + 1]) * t;
else tong -= abs(manghieu[r + 1]) * s;
}
cout << tong << "\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... |