#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
vector<long long> init;
long long n,q,s,t;
struct value{
pair<long long,long long> currentalt;
long long temp;
};
value combine(value v1,value v2){
value ret;
ret.temp = v1.temp + v2.temp;
if (v2.currentalt.first > v1.currentalt.second){
ret.temp -= s*(v2.currentalt.first - v1.currentalt.second);
}
else{
ret.temp += t*(v1.currentalt.second - v2.currentalt.first);
}
ret.currentalt = {v1.currentalt.first,v2.currentalt.second};
return ret;
}
struct node{
node *left,*right;
long long S,E,M;
long long lazy;
value val;
node (long long s,long long e):S(s), E(e){
if (S == E){
val.currentalt.first = init[S];
val.currentalt.second = init[S];
val.temp = 0;
return;
}
M = (S+E)/2;
left = new node(S,M);
right = new node(M+1,E);
lazy = 0;
val = combine(left->val,right->val);
}
void prop(){
if (S == E){
return;
}
M = (S + E) / 2;
if (lazy != 0){
left->val.currentalt.first += lazy;
left->val.currentalt.second += lazy;
right->val.currentalt.first += lazy;
right->val.currentalt.second += lazy;
right->lazy += lazy;
left->lazy += lazy;
lazy = 0;
}
}
value qry(long long l,long long r){
if (l <= S && r >= E){
return val;
}
if (r <= M){
return left->qry(l,r);
}
else if(l > M){
return right->qry(l,r);
}
prop();
return combine(left->qry(l,r), right->qry(l,r));
}
void upd(long long l,long long r,long long v){
if (l > E || r < S){
return;
}
if (l <= S && E <= r){
val.currentalt.first += v ;
val.currentalt.second += v;
lazy += v;
return;
}
prop();
left->upd(l,r,v);
right->upd(l,r,v);
val = combine(left->val,right->val);
}
}*segtree;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> q >> s >> t;
init.resize(n+1);
for(int i = 0;i<=n;i++){
long long alt;cin >> alt;
init[i] = alt;
}
segtree = new node(0,n);
long long ans = 0;
while(q--){
long long l,r,x;cin >> l >> r >> x;
segtree->upd(l,r,x);
value change = segtree->qry(0,n);
ans += change.temp;
cout << ans << '\n';
ans = 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... |