Submission #1353989

#TimeUsernameProblemLanguageResultExecution timeMemory
1353989salehhasanliFoehn Phenomena (JOI17_foehn_phenomena)C++20
100 / 100
295 ms15164 KiB
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;

#define int long long

// vector<int>a(200001,0);



vector<int>t1(800001,0);
vector<int>a1(200001,0);
void build1(int v,int tl, int tr){
    if(tr==tl){
        t1[v] = a1[tl];
    }
    else{
        int tm = (tl+tr)/2;
        build1(v*2,tl,tm);
        build1(v*2+1,tm+1,tr);
        t1[v] = t1[v*2]+t1[v*2+1];
    }
}
int find_sum1(int v, int tl, int tr, int l, int r){
    if(l>r)return 0;
    if(l==tl && r==tr){
        return t1[v];
    }
    int tm = (tl+tr)/2;
    return find_sum1(v*2,tl,tm,l,min(r,tm))+find_sum1(v*2+1,tm+1,tr,max(tm+1,l),r);
}
void update1(int v, int tl, int tr, int pos, int new_val){
    if(tl==tr)t1[v] = new_val;
    else{
        int tm = (tl+tr)/2;
        if(pos<=tm) update1(v*2,tl,tm,pos,new_val);
        else update1(v*2+1,tm+1,tr,pos,new_val);
        t1[v] = t1[v*2]+t1[v*2+1];
    }
}




signed main()
{
    int n,m,s,t;
    cin>>n>>m>>s>>t;
    n++;
    vector<int>a(n);
    for(int i = 0;i<n;i++){
        cin>>a[i];
    }
    
    // int t1 = 0;
    vector<int>y(n);
    for(int i = 0;i<n-1;i++){
        
        y[i] = a[i+1]-a[i ];
    }
    
    vector<int>x;
    for(int i = 0;i<y.size();i++){
        if(y[i]>0){
            a1[i+1] = -s*y[i];
            
        }
        else{
            a1[i+1] = -t*y[i];
        }
    }
    build1(1,1,y.size());
    while(m--){
        int l,r,x;
        cin>>l>>r>>x;
        // cout<<1<<endl;
        
        y[l-1]+=x;
        if(y[l-1]>0){
          update1(1,1,n,l,y[l-1]*(-s));
        }
        else{
          update1(1,1,n,l,y[l-1]*(-t));

        }
                // cout<<1<<endl;

        if(r!=n-1){
            y[r]-=x;
            if(y[r]>0){
              update1(1,1,n,r+1,y[r]*(-s));
            }
            else{
              update1(1,1,n,r+1,y[r]*(-t));

            }
        }
        
        // for(int i:y){
        //     cout<<i<<" ";
        // }
        // cout<<endl;
        
        // cout<<t1<<" "<<l<<" "<<r<<" "<<x<<endl;
        
        cout<<find_sum1(1,1,y.size(),1,y.size())<<endl;
    }
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...