Submission #530670

#TimeUsernameProblemLanguageResultExecution timeMemory
530670ToroTNFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
224 ms17220 KiB
#include<bits/stdc++.h> using namespace std; long long n,t,a,b,arr[200005],diff[200005],l,r,w,seg[800005]; void debug(long long tree,long long st,long long ed) { long long md=(st+ed)/2; if(st==ed) { printf("%lld %lld %lld\n",st,ed,seg[tree]); return; } debug(2*tree,st,md); debug(2*tree+1,md+1,ed); printf("%lld %lld %lld\n",st,ed,seg[tree]); } void build(long long tree,long long st,long long ed) { long long md=(st+ed)/2; if(st==ed) { if(diff[st]>0) { seg[tree]=(-a)*diff[st]; }else { seg[tree]=b*(-diff[st]); } return; } build(2*tree,st,md); build(2*tree+1,md+1,ed); seg[tree]=seg[2*tree]+seg[2*tree+1]; } void update(long long tree,long long st,long long ed,long long idx,long long val) { long long md=(st+ed)/2; if(st==ed) { if(val>0) { seg[tree]=(-a)*val; }else { seg[tree]=b*(-val); } return; } if(idx>md) { update(2*tree+1,md+1,ed,idx,val); }else { update(2*tree,st,md,idx,val); } seg[tree]=seg[2*tree]+seg[2*tree+1]; } int main() { scanf("%lld%lld%lld%lld",&n,&t,&a,&b); for(int i=0;i<=n;i++) { scanf("%lld",&arr[i]); if(i>0) { diff[i]=arr[i]-arr[i-1]; } } build(1,1,n); /*printf("kawin\n"); for(int i=1;i<=n;i++) { printf("%lld ",diff[i]); } printf("\n");*/ //debug(1,1,n); while(t--) { scanf("%lld%lld%lld",&l,&r,&w); if(l>0) { diff[l]+=w; update(1,1,n,l,diff[l]); } if(r+1<=n) { diff[r+1]-=w; update(1,1,n,r+1,diff[r+1]); } /*for(int i=1;i<=n;i++) { printf("%lld ",diff[i]); } printf("\n");*/ printf("%lld\n",seg[1]); } }

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:59:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |     scanf("%lld%lld%lld%lld",&n,&t,&a,&b);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:62:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         scanf("%lld",&arr[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~
foehn_phenomena.cpp:78:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |         scanf("%lld%lld%lld",&l,&r,&w);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...