제출 #1116484

#제출 시각아이디문제언어결과실행 시간메모리
1116484staszic_ojuzFoehn Phenomena (JOI17_foehn_phenomena)C++17
0 / 100
348 ms4880 KiB
#include <bits/stdc++.h>

using namespace std;

using ll=long long;

const int MAX=2*1e5+7;
/*
const int base=1<<20;

ll drzewo[2*base];

void ppush(int a, int b, ll w){
    a += base-1;
    b += base+1;
    while (a/2!=b/2){
        if (a%2==0) drzewo[a+1]+=w;
        if (b%2==1) drzewo[b-1]+=w;
        a/=2;
        b/=2;
    }
}

void get(int a){
    int a2=a;
    a+=base;
    ll wyn=0;
    while (a>0){
        wyn += drzewo[a];
        a /= 2;
    }
    drzewo[base+a2] = wyn;
}
*/
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    ll n, q, l, r;
    ll s, t, x, wyn=0, poprzednia;
    cin >> n >> q >> s >> t;

    ll roznice[MAX];
    cin >> poprzednia;

    for (int i=1; i<=n; i++){
        cin >> x;
        roznice[i] = x-poprzednia;
        if (poprzednia < x) wyn -= s*roznice[i];
        else wyn -= t*roznice[i];
        poprzednia = x;
    }

    for (int i=0; i<q; i++){
        cin >> l >> r >> x;
        //cout << wyn << endl;
        //cout << roznice[l] << " " << roznice[r+1] << endl;
        if (roznice[l] > 0) wyn += s*(roznice[l]);
        else wyn += t*(roznice[l]);

        if (r!=n){
            if (roznice[r+1] > 0) wyn += s*(roznice[r+1]);
            else wyn += t*(roznice[r+1]);
        }

        cout << wyn << endl;
        roznice[l] += x;
        if (r<n) roznice[r+1] -= x;

        if (roznice[l] > 0) wyn -= s*(roznice[l]);
        else wyn -= t*(roznice[l]);

        if (r!=n){
            if (roznice[r+1] > 0) wyn -= s*(roznice[r+1]);
            else wyn -= t*(roznice[r+1]);
        }

        cout << wyn << "\n";
    }

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