제출 #1354083

#제출 시각아이디문제언어결과실행 시간메모리
1354083bimmerFoehn Phenomena (JOI17_foehn_phenomena)C++20
100 / 100
47 ms7288 KiB
#include <bits/stdc++.h>
// #ifndef ONLINE_JUDGE
// #include "algo/debug.h"
// #endif
using namespace std;
#define int long long 
#define endl '\n'
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

const int sz = 2e5 + 5, inf = 1e9, mod = 1e9 + 7;

int a[sz], d[sz], n, q, s, t;

int cost(int x){
    if (x > 0) return -s * x;
    return -t * x;
}

void _(){ 
    cin >> n >> q >> s >> t;
    for (int i = 0; i <= n; i++) {
        cin >> a[i];
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        d[i] = a[i] - a[i - 1];
        ans += cost(d[i]);
    }
    while (q--) {
        int l, r, x;
        cin >> l >> r >> x;
        ans -= cost(d[l]);
        d[l] += x;
        ans += cost(d[l]);
        if (r + 1 <= n) {
            ans -= cost(d[r + 1]);
            d[r + 1] -= x;
            ans += cost(d[r + 1]);
        }
        cout << ans << endl;
    }
}

signed main(){
    cin.tie(nullptr)->sync_with_stdio(0);
    int T = 1;
    // cin >> T;
    while (T--) _();
}
// By Riyad
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...