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;
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define X first
#define Y second
#define sep ' '
#define endl '\n'
#define debug(x) cerr << #x << ": " << x << endl;
const ll MAXN = 1e6 + 10;
ll n, q, s, t, A[MAXN], fen[MAXN], ans;
inline void update(int ind, ll val) {
for (++ind; ind < MAXN; ind += ind & -ind)
fen[ind] += val;
}
inline void update(int l, int r, ll val) {
update(l, val);
update(r + 1, -val);
}
inline ll query(int ind) {
ll ans = 0;
for (++ind; ind > 0; ind -= ind & -ind)
ans += fen[ind];
return ans;
}
inline ll f(ll x, ll y) {
if (x < y) return (x - y) * s;
return (x - y) * t;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> q >> s >> t >> A[0];
for (int i = 1; i <= n; i++) {
cin >> A[i];
ans += f(A[i - 1], A[i]);
update(i, i, A[i]);
}
while (q--) {
ll l, r, x;
cin >> l >> r >> x;
ans -= f(query(l - 1), query(l));
if (r < n) ans -= f(query(r), query(r + 1));
update(l, r, x);
ans += f(query(l - 1), query(l));
if (r < n) ans += f(query(r), query(r + 1));
cout << ans << endl;
}
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... |