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 ar array
#define int long long
const int N = 2e5 + 5;
int a[N], d[N];
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n, q, s, t; cin>>n>>q>>s>>t;
for(int i=0;i<=n;i++) cin>>a[i];
int res = 0;
for(int i=1;i<=n;i++){
d[i] = a[i] - a[i-1];
if(d[i] > 0) res -= d[i] * s;
else res -= d[i] * t;
}
auto upd = [&](int i, int x){
if(i > n) return;
if(d[i] > 0) res += d[i] * s;
else res += d[i] * t;
d[i] += x;
if(d[i] > 0) res -= d[i] * s;
else res -= d[i] * t;
};
while(q--){
int l, r, x; cin>>l>>r>>x;
upd(l, x);
upd(r+1, -x);
cout<<res<<"\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... |