제출 #33275

#제출 시각아이디문제언어결과실행 시간메모리
33275Dat160601Foehn Phenomena (JOI17_foehn_phenomena)C++14
30 / 100
259 ms5140 KiB
#include <bits/stdc++.h> using namespace std; const int N=200007; int n,q,l,r; long long a[N],v,up,down,ans=0,dif[N]; int main(){ cin>>n>>q>>up>>down; cin>>a[0]; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=0;i<n;i++){ if(a[i]<a[i+1]) ans-=up*abs(a[i]-a[i+1]); else ans+=down*abs(a[i]-a[i+1]); } for(int i=0;i<n;i++){ dif[i]=a[i]-a[i+1]; } while(q--){ cin>>l>>r>>v; long long old=dif[l-1]; dif[l-1]-=v; if(old<0) ans+=up*(-old); else ans-=down*old; if(dif[l-1]<0) ans-=up*(-dif[l-1]); else ans+=down*dif[l-1]; if(r<n){ old=dif[r]; dif[r]+=v; if(old<0) ans+=up*(-old); else ans-=down*old; if(dif[r]<0) ans-=up*(-dif[r]); else ans+=down*dif[r]; } printf("%lld\n",ans); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...