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;
map<ll, ll> a, m;
ll n, q, s, t, l, r, x, pos, neg;
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> q >> s >> t;
s *= -1; t *= -1;
a[0] = 0;
for(int i=0; i<=n; i++){
cin >> a[i];
ll tmp = a[i] - a[i-1];
m[i] = tmp;
if(tmp < 0) neg += tmp;
else pos += tmp;
}
for(int i=1; i<=q; i++){
cin >> l >> r >> x;
ll tmp = m[l];
if(tmp >= 0){
pos -= tmp;
tmp += x;
}
else{
neg -= tmp;
tmp += x;
}
if(tmp > 0) pos += tmp;
else neg += tmp;
if(r != n){
tmp = m[r+1];
if(tmp > 0){
pos -= tmp;
tmp -= x;
}
else{
neg -= tmp;
tmp -= x;
}
if(tmp > 0) pos += tmp;
else neg += tmp;
}
ll ans = (s*pos) + (t*neg);
m[l] += x;
m[r+1] -= x;
cout << ans << '\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... |