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;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int N,Q; ll S,T; cin >> N >> Q >> S >> T;
vector<ll> arr(N+1);
for(int i = 0;i<=N;++i) cin >> arr[i];
vector<ll> diff(N);
for(int i = 0;i<N;++i) diff[i] = arr[i]-arr[i+1];
ll ans = 0;
for(int i = 0;i<N;++i){
if(diff[i] < 0) ans += S*diff[i];
else ans += T*diff[i];
}
//cout << ans << "\n";
while(Q--){
int l,r; ll val; cin >> l >> r >> val;
ll x;
if(diff[l-1] < 0) x = S*diff[l-1];
else x = T*diff[l-1];
ans -= x;
diff[l-1] -= val;
if(diff[l-1] < 0) x = S*diff[l-1];
else x = T*diff[l-1];
ans += x;
if(r < N){
if(diff[r] < 0) x = S*diff[r];
else x = T*diff[r];
ans -= x;
diff[r] += val;
if(diff[r] < 0) x = S*diff[r];
else x = T*diff[r];
ans += x;
}
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... |