제출 #33272

#제출 시각아이디문제언어결과실행 시간메모리
33272huynd2001Foehn Phenomena (JOI17_foehn_phenomena)C++14
30 / 100
276 ms33264 KiB
/*huypheu 2 2 5 5 0 6 -1 1 1 4 1 2 8 */ // https://oj.uz/problem/view/JOI17_foehn_phenomena #include <bits/stdc++.h> #define int long long using namespace std; int a[2000007],h[2000007]; signed main() { int n,q,s,t; cin >> n >> q >> s >> t; for(int i=0;i<=n;i++) { cin >> h[i]; if(i>=1) a[i]=h[i]-h[i-1]; } int ans=0; for(int i=1;i<=n;i++) { if(a[i]>0) ans-=a[i]*s; else ans-=a[i]*t; } for(int i=1;i<=q;i++) { int l,r,x; cin >> l >> r >> x; if(l!=0) { if(r!=n) { if(a[l]>0) ans+=a[l]*s; else ans+=a[l]*t; if(a[r+1]>0) ans+=a[r+1]*s; else ans+=a[r+1]*t; a[l]+=x; a[r+1]-=x; if(a[l]>0) ans-=a[l]*s; else ans-=a[l]*t; if(a[r+1]>0) ans-=a[r+1]*s; else ans-=a[r+1]*t; } else { if(a[l]>0) ans+=a[l]*s; else ans+=a[l]*t; a[l]+=x; if(a[l]>0) ans-=a[l]*s; else ans-=a[l]*t; } } else { if(r!=n) { if(a[r+1]>0) ans+=a[r+1]*s; else ans+=a[r+1]*t; a[r+1]-=x; if(a[r+1]>0) ans-=a[r+1]*s; else ans-=a[r+1]*t; } else { } } cout << ans << endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...