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 long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;
#define FOR(i, j, k) for (ll i = j; i < (ll) k; ++i)
#define FORD(i, j, k) for (ll i = j; i >= (ll) k; --i)
#define nl "\n"
#define sp " "
#define all(x) (x).begin(), (x).end()
#define sc second
#define fr first
#define pb emplace_back
struct BIT {
ll n;
vi tree;
BIT(ll N) {
n = N;
tree.resize(n + 1, 0);
}
void add(ll x, ll k) {
while(k <= n) {
tree[k] += x;
k += (k&-k);
}
}
ll sum(ll k) {
ll s = 0;
while(k >= 1) {
s += tree[k];
k -= (k&-k);
}
return s;
}
};
void solve()
{
ll n, q, s, t;
cin >> n >> q >> s >> t;
ll a[n + 1];
FOR(i, 0, n + 1)
cin >> a[i];
auto calc = [&](ll x, ll y) {
if(x < y)
return (x - y) * s;
return (x - y) * t;
};
ll curr = 0;
FOR(i, 1, n + 1) {
curr += calc(a[i - 1], a[i]);
}
BIT bit(n + 5);
FOR(i, 1, n + 1) {
bit.add(a[i] - a[i - 1], i);
}
while(q--) {
int l, r, v;
cin >> l >> r >> v;
curr -= calc(bit.sum(l - 1), bit.sum(l));
if(r != n)
curr -= calc(bit.sum(r), bit.sum(r + 1));
bit.add(v, l);
bit.add(-v, r + 1);
curr += calc(bit.sum(l - 1), bit.sum(l));
if(r != n)
curr += calc(bit.sum(r), bit.sum(r + 1));
cout << curr << nl;
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t = 1;
// cin >> t;
while (t--)
{
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... |