제출 #638696

#제출 시각아이디문제언어결과실행 시간메모리
638696bonkFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
113 ms13156 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n, q, s, t; cin >> n >> q >> s >> t;
    vector<ll>a(n + 1), diff(n + 1);
    ll up = 0, down = 0;

    for(int i = 0; i <= n; i++){
        cin >> a[i];
        if(i) diff[i] = a[i] - a[i - 1];
        if(diff[i] < 0) down += abs(diff[i]);
        else up += diff[i];
    }

    while(q--){
        ll l, r, x; cin >> l >> r >> x;
        if(x > 0){
            if(diff[l] < 0){
                ll tmp = min(abs(diff[l]), x);
                down -= tmp;
                if(x > tmp) up += (x - tmp);
            } else{
                up += x;
            }

            diff[l] += x;

            if(r < n){
                if(diff[r + 1] > 0){
                    ll tmp = min(diff[r + 1], x);
                    up -= tmp;
                    if(x > tmp) down += (x - tmp);
                } else{
                    down += x;
                }

                diff[r + 1] -= x;
            }
        } else{
            if(diff[l] > 0){
                ll tmp = min(diff[l], abs(x));
                up -= tmp;
                if(abs(x) > tmp) down += (abs(x) - tmp);
            } else{
                down += abs(x);
            }

            diff[l] += x;

            if(r < n){
                if(diff[r + 1] < 0){
                    ll tmp = min(abs(diff[r + 1]), abs(x));
                    down -= tmp;
                    if(abs(x) > tmp) up += (abs(x) - tmp);
                } else{
                    up += abs(x);
                }

                diff[r + 1] -= x;
            }
        }

        cout << (down*t - up*s) << '\n';
    }

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