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 ull unsigned long long
#define ld long double
#define fi first
#define se second
ll a[200005], diff[200005];
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n, q;
cin >> n >> q;
ll s, t;
cin >> s >> t;
s = -s, t = -t;
ll ans = 0;
for (int i = 0; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) {
diff[i] = a[i] - a[i - 1];
if (diff[i] > 0) ans += s * diff[i];
else ans += t * diff[i];
}
while (q--) {
int l, r;
ll x;
cin >> l >> r >> x;
if (r == n) {
if (diff[l] > 0) ans -= s * diff[l];
else ans -= t * diff[l];
diff[l] += x;
if (diff[l] > 0) ans += s * diff[l];
else ans += t * diff[l];
cout << ans << "\n";
continue;
}
if (diff[l] > 0) ans -= s * diff[l];
else ans -= t * diff[l];
if (diff[r + 1] > 0) ans -= s * diff[r + 1];
else ans -= t * diff[r + 1];
diff[l] += x, diff[r + 1] -= x;
if (diff[l] > 0) ans += s * diff[l];
else ans += t * diff[l];
if (diff[r + 1] > 0) ans += s * diff[r + 1];
else ans += t * diff[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... |