This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;
#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout (T t, U...u) {cout << t << (sizeof... (u) ? ", " : ""), dout (u...);}
#else
#define debug(...) 7122
#endif
#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second
const int SIZE = 2e5 + 5;
int n, q, s, t;
ll d[SIZE], sum[2];
void solve() {
cin >> n >> q >> s >> t;
FOR (i, 0, n) cin >> d[i];
for (int i = n; i >= 1; i--) d[i] -= d[i - 1];
FOR (i, 1, n) {
if (d[i] > 0) sum[0] += d[i];
else sum[1] += -d[i];
}
while (q--) {
int l, r, k;
cin >> l >> r >> k;
if (d[l] > 0) sum[0] -= d[l];
else sum[1] -= -d[l];
if (r < n) {
if (d[r + 1] > 0) sum[0] -= d[r + 1];
else sum[1] -= -d[r + 1];
}
d[l] += k, d[r + 1] -= k;
if (d[l] > 0) sum[0] += d[l];
else sum[1] += -d[l];
if (r < n) {
if (d[r + 1] > 0) sum[0] += d[r + 1];
else sum[1] += -d[r + 1];
}
cout << -sum[0] * s + sum[1] * t << '\n';
}
}
int main() {
Waimai;
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |