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 int long long
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int n,q,s,t; cin>>n>>q>>s>>t;
int a[n+5];
for(int i=0; i<=n; i++) cin>>a[i];
int d[n+5];
for(int i=1; i<=n; i++) d[i] = a[i] - a[i-1];
int tot=0;
for(int i=1; i<=n; i++){
if(d[i]>0) tot -= (s*d[i]); //altitude inc so temp dec
else tot -= (t*d[i]); //altitude dec so temp inc
}
for(int i=0; i<q; i++){
int l,r,x; cin>>l>>r>>x;
if(d[l]>0) tot += (s*d[l]);
else tot += (t*d[l]);
d[l] += x;
if(d[l]>0) tot -= (s*d[l]);
else tot -= (t*d[l]);
if(r==n){ cout<<tot<<"\n"; continue;}
if(d[r+1]>0) tot += (s*d[r+1]);
else tot += (t*d[r+1]);
d[r+1] -= x;
if(d[r+1]>0) tot -= (s*d[r+1]);
else tot -= (t*d[r+1]);
cout<<tot<<"\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... |