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;
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
long long n, q, s, t;
cin >> n >> q >> s >> t;
long long alt[n+1];
for (long long i=0; i<n+1; i++) {
cin >> alt[i];
}
long long dlt[n];
for (long long i=0; i<n; i++) {
dlt[i] = alt[i+1] - alt[i];
}
s = - s;
t = - t;
long long init = 0;
for (long long i=0; i<n; i++) {
if (dlt[i] < 0) init += t * dlt[i];
else init += s * dlt[i];
}
for (long long i=0; i<q; i++) {
long long l, r, x;
cin >> l >> r >> x;
l--; r--;
long long al = l;
long long ar = r+1;
long long old = dlt[al];
long long old_c = (old > 0 ? old * s : old * t);
long long ne = dlt[al] + x;
long long ne_c = (ne > 0 ? ne * s : ne * t);
init -= old_c;
init += ne_c;
dlt[al] += x;
if (ar != n) {
long long old = dlt[ar];
long long old_c = (old > 0 ? old * s : old * t);
long long ne = dlt[ar] - x;
long long ne_c = (ne > 0 ? ne * s : ne * t);
init -= old_c;
init += ne_c;
dlt[ar] -= x;
}
cout << init << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |