Submission #873495

#TimeUsernameProblemLanguageResultExecution timeMemory
873495NintsiChkhaidzeFoehn Phenomena (JOI17_foehn_phenomena)C++17
30 / 100
1088 ms4768 KiB
#include <bits/stdc++.h>
#define pb push_back
#define s second
#define f first
#define ll long long
#define left (h<<1),l,((l + r)>>1)
#define right ((h<<1)|1),((l + r)>>1) + 1,r
#define pii pair<int,int>
#define int ll
using namespace std;

const int N = 2e5 + 5;
int a[N],A[N],b[N],S,T;

int getans(int x,int y){
    if (x < y) return -S*(y-x);
    return (x - y)*T;
}

void upd(int h,int l,int r,int L,int R,int val){
    //neli
    for (int i = L; i <= R; i++)
        b[i] += val;
}
int get(int h,int l,int r,int idx){
    return b[idx];
}

void UPD(int h,int l,int r,int L,int R,int val){
    for (int i = L; i <= R; i++)
        A[i] += val;
}

int GET(int h,int l,int r,int idx){
    return A[idx];
}

signed main (){
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    
    int n,q;
    cin>>n>>q>>S>>T;

    ++n;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        int val = getans(a[i - 1],a[i]);
        upd(1,1,n,i,n,val);
        UPD(1,1,n,i,i,a[i]);
    }

    while (q--){
        int l,r,x;
        cin>>l>>r>>x;
        l++,r++;
        UPD(1,1,n,l,r,x); 

        int newx = GET(1,1,n,l - 1);
        int newy = GET(1,1,n,l);

        int oldx = newx;
        int oldy = newy - x;

        int oldval = getans(oldx,oldy);
        int newval = getans(newx,newy);
        upd(1,1,n,l,n,newval - oldval);

        if (r + 1 <= n){
            newx = GET(1,1,n,r);
            newy = GET(1,1,n,r+1);
            oldx = newx - x;
            oldy = newy;

            oldval = getans(oldx,oldy);
            newval = getans(newx,newy);
            upd(1,1,n,r+1,n,newval - oldval);
        }
        
        cout<<get(1,1,n,n)<<endl;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...