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;
const int mxn = 2e5+5;
int n, q;
ll s, t;
ll a[mxn], fen[mxn];
ll ans = 0;
void add(int i, int x) {
while(i <= n) {
fen[i] += x;
i += i&(-i);
}
}
ll get(int i) {
ll ans = 0; while(i) {
ans += fen[i];
i -= i&(-i);
} return ans;
}
ll diff_to_delta(ll diff) {
return diff > 0 ? -s*diff : -t*diff;
}
int main(int argc, char const *argv[]) {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> q >> s >> t;
n++;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i < n; i++) {
add(i, a[i+1]-a[i]);
ans += diff_to_delta(a[i+1]-a[i]);
}
for(int i = 0; i < q; i++) {
int l, r, x; cin >> l >> r >> x; l++, r++;
if(l > 1) {
ll diff = get(l-1)-(l-2 > 0 ? get(l-2) : 0);
ans -= diff_to_delta(diff);
add(l-1, x);
diff = get(l-1)-(l-2 > 0 ? get(l-2) : 0);
ans += diff_to_delta(diff);
}
if(r < n) {
ll diff = get(r)-get(r-1);
ans -= diff_to_delta(diff);
add(r, -x);
diff = get(r)-get(r-1);
ans += diff_to_delta(diff);
}
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... |