#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define st first
#define nd second
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define debug false
const int MAXN = 200 * 1000 + 1738;;
ll a[MAXN];
ll tr[MAXN];
int main () {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, q;
ll s, t;
cin >> n >> q >> s >> t;
n ++;
for (int i = 1; i <= n; i ++) {
cin >> a[i];
}
for (int i = 2; i <= n; i ++) {
tr[i] = a[i] - a[i - 1];
}
ll sd = 0, su = 0;
for (int i = 2; i <= n; i ++) {
if (tr[i] > 0) {
sd += tr[i];
} else {
su += tr[i];
}
}
int l, r;
ll x;
if (debug) {
cout << "roznice: " << "\n";
for (int i = 1; i <= n; i ++) {
cout << tr[i] << " ";
}
cout << "\n";
}
while (q --) {
cin >> l >> r >> x;
l ++;
r ++;
if (tr[l] > 0) {
sd -= tr[l];
} else {
su -= tr[l];
}
tr[l] += x;
if (tr[l] > 0) {
sd += tr[l];
} else {
su += tr[l];
}
if (r != n) {
r ++;
if (tr[r] > 0) {
sd -= tr[r];
} else {
su -= tr[r];
}
tr[r] -= x;
if (tr[r] > 0) {
sd += tr[r];
} else {
su += tr[r];
}
}
cout << (-1LL) * (sd * s + su * t) << "\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... |