Submission #854601

#TimeUsernameProblemLanguageResultExecution timeMemory
854601cjtsaiFoehn Phenomena (JOI17_foehn_phenomena)C++14
10 / 100
81 ms7504 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main(){ ios_base::sync_with_stdio(false);cin.tie(0); int n, q, s, t; cin>>n>>q>>s>>t; vector<int> alt(n+1); vector<int> pre(n+1, 0); for(int i=0; i<=n; i++) cin>>pre[i]; alt[0]=0; int ans=0; for(int i=1; i<=n; i++) {alt[i]=pre[i]-pre[i-1];ans-=(alt[i]*(alt[i]>0?s:t));}//cout<<ans<<'\n';} //cout<<ans; for(int i=0; i<q; i++){ int l, r, x;cin>>l>>r>>x; if((alt[l]>=0||alt[l]<=-1*x)&&x>=0){ //cout<<'a'; ans-=(x*(alt[l]>=0?s:t)); }else if((alt[l]<=0||alt[l]>=x)&&x<0){ ans-=(x*(alt[l]<=0?t:s)); //cout<<'b'; }else if(alt[l]<0){ ans+=(alt[l]*t); ans+=((alt[l]+x)*(-1)*s); //cout<<"c"; } else if(alt[l]>0){ //cout<<'d'; ans+=(alt[l]*s); ans+=((x-alt[l])*t); } if(r!=n){ if((alt[r+1]>=0||alt[r+1]<=-1*x)&&x>=0){ ans+=(x*(alt[r+1]>=0?s:t)); }else if((alt[r+1]<=0||alt[r+1]>=x)&&x<0){ ans+=(x*(alt[r+1]<=0?t:s)); }else if(alt[r+1]<0){ ans-=(alt[r+1]*s); ans-=((alt[r+1]+x)*(-1)*t); } else if(alt[r+1]>0){ ans-=(alt[r+1]*t); ans-=((x-alt[r+1])*s); } //alt[l]+=x; alt[r+1]-=x;} alt[l]+=x; //for(int x:alt) cout<<x<<' '; cout<<ans<<'\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...