Submission #33277

#TimeUsernameProblemLanguageResultExecution timeMemory
33277huynd2001Foehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
196 ms9828 KiB
/*huypheu 7 8 8 13 0 4 -9 4 -2 3 10 -9 1 4 8 3 5 -2 3 3 9 1 7 4 3 5 -1 5 6 3 4 4 9 6 7 -10 */ // https://oj.uz/problem/view/JOI17_foehn_phenomena #include <bits/stdc++.h> #define int long long using namespace std; int a[200007],h[200007]; int la[200007],ra[200007],xa[200007]; signed main() { // ios_base::sync_with_stdio(false); // cin.tie(0); int n,q,s,t; // cin >> n >> q >> s >> t; // printf("lz"); scanf("%lld %lld %lld %lld",&n,&q,&s,&t); for(int i=0;i<=n;i++) { // cin >> h[i]; scanf("%lld",&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++) { // cin >> la[i] >> ra[i] >> xa[i]; scanf("%lld %lld %lld",&la[i],&ra[i],&xa[i]); } // printf("lz"); for(int i=1;i<=q;i++) { int l,r,x; l=la[i],r=ra[i],x=xa[i]; 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; printf("%lld\n",ans); } return 0; }

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:35:42: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld %lld %lld",&n,&q,&s,&t);
                                          ^
foehn_phenomena.cpp:39:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld",&h[i]);
                      ^
foehn_phenomena.cpp:50:47: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld %lld",&la[i],&ra[i],&xa[i]);
                                               ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...