Submission #129304

#TimeUsernameProblemLanguageResultExecution timeMemory
129304lamkhanhFoehn Phenomena (JOI17_foehn_phenomena)C++17
0 / 100
1006 ms3736 KiB
#include<bits/stdc++.h> using namespace std; const int MaxN = 200002; int a[MaxN], kc[MaxN]; short int type[MaxN]; int n, q, s, t, l, r, x, i; long long ans; main(){ 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"; } }

Compilation message (stderr)

foehn_phenomena.cpp:10:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...