제출 #1280782

#제출 시각아이디문제언어결과실행 시간메모리
1280782dhuyyyyFoehn Phenomena (JOI17_foehn_phenomena)C++20
100 / 100
67 ms7308 KiB
#include<bits/stdc++.h>
#define fi first
#define se second
#define int long long
using namespace std;

using ll = long long;
using ii = pair<int, int>;
using aa = array<int,3>;

const int N = 5e5+5;

int n, m, S, T, l, r, k, t1, t2, ans = 0;

int a[N], b[N];

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cin >> n >> m >> S >> T;
    for (int i = 0; i <= n; i++){
         cin >> a[i];
    }
    for (int i = 1; i <= n; i++){
        b[i] = a[i] - a[i-1];
        if (b[i] > 0) ans -= S * (b[i]);
        else ans += T * (-b[i]);
    }
    for (int i = 1; i <= m; i++){
        cin >> l >> r >> k;
        if (b[l] > 0) ans += S * b[l];
        else ans -= T * (-b[l]);
        b[l] += k;
        b[r + 1] -= k;
        if (b[l] > 0) ans -= S * (b[l]);
        else ans += T * (-b[l]);
        if (r + 1 <= n){
            if (b[r + 1] + k > 0) ans += S * (b[r + 1] + k);
            else ans -= T * (-(b[r + 1] + k));
            if (b[r + 1] > 0) ans -= S * (b[r + 1]);
            else ans += T * (-b[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...