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