Submission #203628

#TimeUsernameProblemLanguageResultExecution timeMemory
203628thebesFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
181 ms13176 KiB
#include <bits/stdc++.h>
#define DEBUG 1
using namespace std;

namespace output{
    void __(short x){cout<<x;}
    void __(unsigned x){cout<<x;}
    void __(int x){cout<<x;}
    void __(long long x){cout<<x;}
    void __(unsigned long long x){cout<<x;}
    void __(double x){cout<<x;}
    void __(long double x){cout<<x;}
    void __(char x){cout<<x;}
    void __(const char*x){cout<<x;}
    void __(const string&x){cout<<x;}
    void __(bool x){cout<<(x?"true":"false");}
    template<class S,class T>
    void __(const pair<S,T>&x){__(DEBUG?"(":""),__(x.first),__(DEBUG?", ":" "),__(x.second),__(DEBUG?")":"");}
    template<class T>
    void __(const vector<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
    template<class T>
    void __(const set<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
    template<class T>
    void __(const multiset<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
    template<class S,class T>
    void __(const map<S,T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
    void pr(){cout<<"\n";}
    template<class S,class... T>
    void pr(const S&a,const T&...b){__(a);if(sizeof...(b))__(' ');pr(b...);}
}

using namespace output;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef pair<ld,ld> pld;
typedef vector<int> vi;
typedef vector<ll> vl;

#define pb push_back
#define fox(i,x,y) for(int i=(x);i<=(y);i++)
#define foxr(i,x,y) for(int i=(y);i>=(x);i--)

const ll MN = 2e5+5;
ll N, Q, S, T, A[MN], arr[MN], x, y, k, i, ans;

int main(){
    scanf("%lld%lld%lld%lld",&N,&Q,&S,&T);
    for(i=0;i<=N;i++) scanf("%lld",&A[i]);
    for(i=1;i<=N;i++){
        arr[i]=A[i-1]-A[i];
        ans+=arr[i]>=0?arr[i]*T:arr[i]*S;
    }
    for(;Q;Q--){
        scanf("%lld%lld%lld",&x,&y,&k); y++; k*=-1; ll kk = k;
        if(arr[x]<=0){
            if(k>=0){
                ll D = min(-arr[x],k);
                k -= D; arr[x] += D; ans += S*D;
                if(k) arr[x]+=k, ans += T*k;
            }
            else arr[x]+=k, ans += S*k;
        }
        else{
            if(k<=0){
                ll D = min(arr[x],-k);
                k += D, arr[x] -= D; ans -= T*D;
                if(k) arr[x]+=k, ans += S*k;
            }
            else arr[x]+=k, ans += T*k;
        }
        if(y==N+1){
            printf("%lld\n",ans);
            continue;
        }
        x = y; k = -kk;
        if(arr[x]<=0){
            if(k>=0){
                ll D = min(-arr[x],k);
                k -= D; arr[x] += D; ans += S*D;
                if(k) arr[x]+=k, ans += T*k;
            }
            else arr[x]+=k, ans += S*k;
        }
        else{
            if(k<=0){
                ll D = min(arr[x],-k);
                k += D, arr[x] -= D; ans -= T*D;
                if(k) arr[x]+=k, ans += S*k;
            }
            else arr[x]+=k, ans += T*k;
        }
        printf("%lld\n",ans);
    }
    return 0;
}

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:51:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld%lld%lld%lld",&N,&Q,&S,&T);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:52:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=0;i<=N;i++) scanf("%lld",&A[i]);
                       ~~~~~^~~~~~~~~~~~~~
foehn_phenomena.cpp:58:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld%lld",&x,&y,&k); y++; k*=-1; ll kk = k;
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...