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<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<utility>
#define int long long
#define INF 1000000000000000000
using namespace std;
signed main() {
int n, q, s, t;
cin >> n >> q >> s >> t;
vector<int>v(n+5), dif(n+5);
for (int i = 0 ; i <= n ; i++) cin >> v[i];
int ans = 0;
for (int i = 0 ; i < n ; i++) {
dif[i] = v[i+1] - v[i];
if (dif[i] > 0) ans -= s * dif[i];
else ans += t * (-dif[i]);
}
//cout << ans << "\n";
int l, r, x;
while (q--) {
cin >> l >> r >> x;
if (dif[l-1] > 0) ans += s * dif[l-1];
else ans -= t * -(dif[l-1]);
dif[l-1] += x;
if (dif[l-1] > 0) ans -= s * dif[l-1];
else ans += t * -(dif[l-1]);
if (r != n) {
if (dif[r] > 0) ans += s * dif[r];
else ans -= t * -(dif[r]);
dif[r] -= x;
if (dif[r] > 0) ans -= s * dif[r];
else ans += t * -(dif[r]);
}
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... |