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>
#define ll long long
using namespace std;
int main(){
ll n,q,s,t;cin>>n>>q>>s>>t;
ll arr[n+5],sel[n+5];
// 1 3 2 4 5 1
// 0 2 0
ll sumpo=0;
ll sumne=0;
for(int i=0;i<=n;i++){
cin>>arr[i];
if(i!=0){
sel[i]=arr[i]-arr[i-1];
if(sel[i]>0) sumpo+=sel[i];
else sumne+=sel[i];
}
}
for(int i=1;i<=q;i++){
ll l,r,x;cin>>l>>r>>x;
if(sel[l]>0) sumpo-=sel[l];
else sumne-=sel[l];
sel[l]=sel[l]+x;
if(sel[l]>0) sumpo+=sel[l];
else sumne+=sel[l];
if(r!=n){
if(sel[r+1]>0) sumpo-=sel[r+1];
else sumne-=sel[r+1];
sel[r+1]=sel[r+1]+-1*x;
if(sel[r+1]>0) sumpo+=sel[r+1];
else sumne+=sel[r+1];
}
ll ans=sumpo*-1*s+sumne*-1*t;
cout<<ans<<endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |