#include <bits/stdc++.h>
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define int long long
#define ld long double
#define ll long long
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
using namespace std;
const int oo = 1e18 + 9;
const int MAX = 2e5 + 5, LOGMAX = 20, B = 441, MOD = 998244353;
int tree[MAX];
int ask(int l, int r){
if(l != 1) return ask(1, r) - ask(1, l - 1);
int res = 0;
for(int i = r; i > 0; i -= i & -i) res += tree[i];
return res;
}
void update(int pos, int val){
for(int i = pos; i < MAX; i += i & -i) tree[i] += val;
}
int tot = 0;
int n, q, s, t;
int f(int i){
if(i == n + 1) return 0;
int a = ask(1, i), b = ask(1, i + 1);
if(a < b) return s * (a - b);
else return t * (a - b);
}
void solve(){
cin >> n >> q >> s >> t;
for(int i = 1; i <= n + 1; i++){
int a; cin >> a;
update(i, a);
update(i + 1, -a);
}
for(int i = 1; i <= n; i++){
tot += f(i);
}
while(q--){
int l, r, a; cin >> l >> r >> a;
l++; r++;
tot -= f(l-1);
tot -= f(r);
update(l, a);
update(r + 1, -a);
tot += f(l-1);
tot += f(r);
cout << tot << '\n';
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while(t--) 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... |