#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define pb push_back
#define int long long
#define fi first
#define se second
const int N = 3e5 + 5, M = 1e9 + 7, LG = 20;
int n , A[N] , Fen[N] , t , l , r , v , q , s;
void add(int i , int x){
while(i <= n){
Fen[i] += x;
i += (i&(-i));
}
}
int prep(int i){
int ans = 0;
while(i>0){
ans += Fen[i];
i -= (i&(-i));
}
return ans;
}
void solve(){
cin >> n >> q >> s >> t;
int ans = 0;
cin >> A[0];
for (int i=1 ; i<=n ; i++){
cin >> A[i];
if (A[i-1] <= A[i]){
ans -= (A[i] - A[i-1])*s;
}else{
ans += (A[i-1]-A[i])*t;
}
}
while(q--){
cin >> l >> r >> v;
int L = A[l-1] + prep(l-1) , R = A[r+1] + prep(r+1);
int Lc = A[l] + prep(l) , Rc = A[r] + prep(r);
if (v >= 0){
if (L > Lc){
if (L > Lc + v){
ans -= v*t;
}else{
ans -= (L-Lc)*t;
ans -= (Lc+v-L)*s;
}
}else{
ans -= v*s;
}
bool p = 1;
if (r == n) p = 0;
if (p){
if (R > Rc){
if (R > Rc + v){
ans += v*s;
}else{
ans += (R-Rc)*s;
ans += (Rc+v-R)*t;
}
}else{
ans += v*t;
}
}
}else{
// cout << ans << ' ' << L << ' ' << Lc << ' ' << Rc << ' ' << R << ' ' << v << endl;
if (L < Lc){
if (L < Lc + v){
ans += abs(v)*s;
}else{
ans += (Lc-L)*s;
ans += (Lc+v-L)*t;
}
}else{
ans += abs(v)*t;
}
bool p = 1;
if (r == n) p = 0;
if (p){
if (R < Rc){
if (R < Rc + v){
ans -= abs(v)*t;
}else{
ans -= (Rc-R)*t;
ans -= (Rc+v-R)*s;
}
}else{
ans -= s*abs(v);
}
}
}
cout << ans << endl;
add(l,v);
add(r+1,-v);
}
}
signed main(){
// freopen("" , "r" , stdin);
// freopen("" , "w" , stdout);
// cout << setprecision(30);
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int ts = 1;
// cin >> ts;
while(ts--){
solve();
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |