Submission #129319

#TimeUsernameProblemLanguageResultExecution timeMemory
129319lamkhanhFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
161 ms8948 KiB
#include<bits/stdc++.h> #pragma GCC optimize ("O3") using namespace std; const int MaxN = 200002; long long a[MaxN], kc[MaxN]; long long type[MaxN]; long long n, q, s, t, l, r, x, i; long long ans; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> q >> s >> t; for(i=0;i<=n;i++) cin >> a[i]; for(i=0;i<=n-1;i++){ kc[i] = a[i]-a[i+1]; if(kc[i]>=0) type[i] = 0; else type[i] = 1; ans += ((!type[i]) ? t : s)*kc[i]; } for(i=0;i<q;i++){ cin >> l >> r >> x; kc[l-1] -= x; if(kc[l-1]>=0&&type[l-1]){ type[l-1] = 0; ans = ans + kc[l-1]*t - (kc[l-1]+x)*s; } else if(kc[l-1]<0&&!type[l-1]){ type[l-1] = 1; ans = ans + kc[l-1]*s - (kc[l-1]+x)*t; } else if(kc[l-1]>=0&&!type[l-1]) ans -= x*t; else ans -= x*s; if(r<n){ kc[r] += x; if(kc[r]>=0&&type[r]){ type[r] = 0; ans = ans + kc[r]*t - (kc[r]-x)*s; } else if(kc[r]<0&&!type[r]){ type[r] = 1; ans = ans + kc[r]*s - (kc[r]-x)*t; } else if(kc[r]>=0&&!type[r]) ans += x*t; else ans += x*s; } cout << ans << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...