제출 #1290301

#제출 시각아이디문제언어결과실행 시간메모리
1290301hahaFoehn Phenomena (JOI17_foehn_phenomena)C++20
100 / 100
68 ms7352 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long

const int maxn = 200005;
ll a[maxn], diff[maxn];
int n, q;
ll S, T;

ll cost(ll x) {
    if (x > 0) return -S * x;
    else return -T * x;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n >> q >> S >> T;
    for (int i = 0; i <= n; i++) cin >> a[i];

    for (int i = 1; i <= n; i++) diff[i] = a[i] - a[i - 1];

    ll ans = 0;
    for (int i = 1; i <= n; i++) ans += cost(diff[i]);

    while (q--) {
        int L, R;
        ll X;
        cin >> L >> R >> X;

        // Remove old contributions
        ans -= cost(diff[L]);
        diff[L] += X;
        ans += cost(diff[L]);

        if (R + 1 <= n) {
            ans -= cost(diff[R + 1]);
            diff[R + 1] -= X;
            ans += cost(diff[R + 1]);
        }

        cout << ans << '\n';
    }

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...