Submission #1272123

#TimeUsernameProblemLanguageResultExecution timeMemory
1272123nonjapenzilFoehn Phenomena (JOI17_foehn_phenomena)C++20
100 / 100
204 ms7284 KiB
#include <bits/stdc++.h>
using namespace std;
#define pf(a) printf("%.9f", a)
#define SZ size()
#define ll long long
#define pb push_back
#define BBC ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
void W2dNHK() {
    ll n,q,s,t;
    cin>>n>>q>>s>>t;
    ll i;
    ll k[n+11];
    ll z[n+11];
    ll ans=0;
    for(i=0 ; i<=n ; i++ ){
        cin>>k[i];
        if(i>0){
            z[i]=k[i]-k[i-1];
            if(z[i]>=0){
                ans-=s*z[i];
            }
            else{
                ans-=t*z[i];
            }
        }
    }
    while(q--){
        ll l,r,x;
        cin>>l>>r>>x;
        ll zl=z[l];
        z[l]+=x;
        if(zl>=0){
            if(z[l]>=0){
                ans-=(z[l]-zl)*s;
            }
            else{
                ans+=zl*s;
                ans-=z[l]*t;
            }
        }
        else{
            if(z[l]<0){
                ans-=(z[l]-zl)*t;
            }
            else{
                ans+=zl*t;
                ans-=z[l]*s;
            }
        }
        if(r==n){
            cout<<ans<<endl;
            continue;
        }
        ll zr=z[r+1];
        z[r+1]-=x;
        if(zr>=0){
            if(z[r+1]>=0){
                ans-=(z[r+1]-zr)*s;
            }
            else{
                ans+=zr*s;
                ans-=z[r+1]*t;
            }
        }
        else{
            if(z[r+1]<0){
                ans-=(z[r+1]-zr)*t;
            }
            else{
                ans+=zr*t;
                ans-=z[r+1]*s;
            }
        }
        cout<<ans<<endl;
    }

}
int main() {
    BBC
    ll tc = 1;
    //cin>>tc;
    while (tc--) {
        W2dNHK();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...