This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[200100];
ll t[1200100];
int n, q, S, T;
void build(int v, int l, int r){
if(l == r){
if(a[l] < 0) t[v] = -a[l] * T;
else t[v] = -a[l] * S;
return;
}
int mid=(l+r)/2;
build(v+v, l, mid);
build(v+v+1, mid+1, r);
t[v] = t[v + v] + t[v+v+1];
}
void upd(int v, int l, int r, int pos, ll x){
if(l == r){
a[l] += x;
if(a[l] < 0) t[v] = -a[l] * T;
else t[v] = -a[l] * S;
return;
}
int mid = (l + r)/2;
if(mid >= pos) upd(v+v, l, mid, pos, x);
else upd(v+v+1, mid+1, r, pos, x);
t[v] = t[v+v] + t[v+v+1];
}
int main(){
cin>>n>>q>>S>>T;
for(int i=0; i<=n; i++){
cin>>a[i];
}
for(int i=n; i>=1; i--) a[i] = a[i] - a[i - 1];
build(1, 1, n);
//cout<<t[1]<<'\n';
for(int i=1; i<=q; i++){
int l, r, x;
cin>>l>>r>>x;
upd(1, 1, n, l, x);
if(r + 1 <= n) upd(1, 1, n, r + 1, -x);
cout<<t[1]<<'\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |