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;
typedef long long ll;
const int mxn = 2e5+5;
ll arr[mxn];
ll diff[mxn];
int main()
{
ll n, q, S, T;
cin >> n >> q >> S >> T;
for(int i = 0; i <= n; i++) {
cin >> arr[i];
}
ll ans = 0;
for(int i = 1; i <= n; i++) {
ll d = arr[i]-arr[i-1];
diff[i] = d;
if(d>0) {
ans-=(abs(d)*S);
}
else {
ans+=(abs(d)*T);
}
//cout << ans << '\n';
}
//cout << ans << '\n';
while(q--) {
ll l, r, x;
cin >> l >> r >> x;
if(diff[l]>0) ans += (abs(diff[l])*S);
else ans -= (abs(diff[l])*T);
diff[l]+=x;
if(diff[l]>0) ans -= (abs(diff[l])*S);
else ans += (abs(diff[l])*T);
if(r+1<=n) {
if(diff[r+1]>0) ans += (abs(diff[r+1])*S);
else ans -= (abs(diff[r+1])*T);
diff[r+1]-=x;
if(diff[r+1]>0) ans -= (abs(diff[r+1])*S);
else ans += (abs(diff[r+1])*T);
}
cout << ans << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |