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;
/*
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
*/
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define sz(x) (int)x.size()
using ll = long long;
const int mod = 1e9+7;
int calc(int a, int s, int t) {
return (a > 0 ? -a*s : -a*t);
}
void solve(int tc) {
int n, q, s, t;
cin >> n >> q >> s >> t;
int ans = 0;
vector<int> v(n+1);
for (auto &x : v) cin >> x;
vector<int> d(n+1);
for (int i = 1; i <= n; ++i) {
d[i] = v[i] - v[i-1];
ans += calc(d[i], s, t);
}
while (q--) {
int l, r, x;
cin >> l >> r >> x;
ans += calc(d[l] + x, s, t) - calc(d[l], s, t);
d[l] += x;
if (r != n) {
ans += calc(d[r+1]-x, s, t) - calc(d[r+1], s, t);
d[r+1] -= x;
}
cout << ans << '\n';
}
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int tc = 1;
//cin >> tc;
for (int i = 1; i <= tc; ++i) solve(i);
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... |