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;
using ll = long long;
using pll = pair<ll, ll>;
inline void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
const ll INF = 1e16;
ll n, q, s, t, sum;
ll arr[200005], diff[200005];
ll cal(ll x) {
if (x < 0) {
return -t * x;
} else {
return -s * x;
}
}
int main() {
fastio();
cin >> n >> q >> s >> t;
for (ll i = 0; i <= n; i++) {
cin >> arr[i];
}
for (ll i = 1; i <= n; i++) {
diff[i] = arr[i] - arr[i - 1];
sum += cal(diff[i]);
}
ll l, r, x;
while (q--) {
cin >> l >> r >> x;
sum -= cal(diff[l]) + (r != n) * cal(diff[r + 1]);
diff[l] += x;
diff[r + 1] -= (r != n) * x;
sum += cal(diff[l]) + (r != n) * cal(diff[r + 1]);
cout << sum << '\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... |