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 pb push_back
const int mxN = 1e6 + 5;
ll n,q,s,t,a[mxN],b[mxN];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll ans = 0;
cin >> n >> q >> s >> t;
s *= -1;
for(int i = 0; i <= n; i++){
cin >> a[i];
if(i){
b[i] = a[i - 1] - a[i];
ans += ((b[i] < 0) ? s : t) * abs(b[i]);
}
}
while(q--){
ll x,l,r;
cin >> l >> r >> x;
if(l != 0){
ans -= ((b[l] < 0) ? s : t) * abs(b[l]);
b[l] -= x;
ans += ((b[l] < 0) ? s : t) * abs(b[l]);
}
if(r != n){
ans -= ((b[r + 1] < 0) ? s : t) * abs(b[r + 1]);
b[r + 1] += x;
ans += ((b[r + 1] < 0) ? s : t) * abs(b[r + 1]);
}
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... |