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
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false)
const int lmt=2e5+5;
ll a[lmt],n,q,s,t,ans=0,ad[3*lmt];
void updet(int at,int L,int R,int l,int r,ll u){
if(r<L || R<l) return;
if(l<=L && R<=r){
ad[at]+=u;
return;
}
int mid=(L+R)/2;
updet(at*2,L,mid,l,r,u);
updet(at*2+1,mid+1,R,l,r,u);
}
ll query(int at,int L,int R,int pos){
if(pos<L || R<pos) return 0LL;
if(L==R){
return a[L]+ad[at];
}
int mid=(L+R)/2;
if(pos<=mid){
return query(at*2,L,mid,pos)+ad[at];
}else{
return query(at*2+1,mid+1,R,pos)+ad[at];
}
}
int main(){
fastio;
cin>>n>>q>>s>>t;
for(int i=0;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
if(a[i-1]<a[i]){
ans+=((a[i-1]-a[i])*s);
}else{
ans+=((a[i-1]-a[i])*t);
}
}
while(q--){
ll l,r,x;
cin>>l>>r>>x;
ll b=query(1,1,n,l-1),c=query(1,1,n,l);
if(b<c){
ans-=((b-c)*s);
}else{
ans-=((b-c)*t);
}
c+=x;
if(b<c){
ans+=((b-c)*s);
}else{
ans+=((b-c)*t);
}
if(r<n){
b=query(1,1,n,r),c=query(1,1,n,r+1);
if(b<c){
ans-=((b-c)*s);
}else{
ans-=((b-c)*t);
}
b+=x;
if(b<c){
ans+=((b-c)*s);
}else{
ans+=((b-c)*t);
}
}
updet(1,1,n,l,r,x);
cout<<ans<<endl;
}
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... |