Submission #421723

#TimeUsernameProblemLanguageResultExecution timeMemory
421723juggernautSnowball (JOI21_ho_t2)C++17
100 / 100
131 ms14072 KiB
#include<bits/stdc++.h> #define fr first #define sc second using namespace std; void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);} typedef long long ll; #define USING_ORDERED_SET 0 #if USING_ORDERED_SET #include<bits/extc++.h> using namespace __gnu_pbds; template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; #endif template<class T>void umax(T &a,T b){if(a<b)a=b;} template<class T>void umin(T &a,T b){if(b<a)a=b;} #ifdef IOI2021SG #define printl(args...)printf(args) #else #define printl(args...)((void)0) #endif int n,q; ll a[200005]; ll l[200005]; ll r[200005]; ll ans[200005]; bool dir[200005]; int main(){ scanf("%d%d",&n,&q); for(int i=1;i<=n;i++)scanf("%lld",&a[i]); ll cnt=0; for(int i=1;i<=q;i++){ ll x; scanf("%lld",&x); cnt+=x; l[i]=min(l[i-1],cnt); r[i]=max(r[i-1],cnt); dir[i]=(x>0); } ans[1]-=l[q]; ans[n]+=r[q]; for(int i=1;i<n;i++){ if(a[i]+r[q]<=a[i+1]+l[q]){ ans[i]+=r[q]; ans[i+1]-=l[q]; }else{ int l=1,r=q; while(l<r){ int mid=(l+r)>>1; if(a[i]+::r[mid]>a[i+1]+::l[mid])r=mid; else l=mid+1; } if(dir[l]){ ans[i]+=max(0ll,a[i+1]+::l[l-1]-a[i]); ans[i+1]+=max(0ll,a[i+1]-(a[i+1]+::l[l-1])); }else{ ans[i]+=max(0ll,a[i]+::r[l-1]-a[i]); ans[i+1]+=max(0ll,a[i+1]-a[i]-::r[l-1]); } } } for(int i=1;i<=n;i++)printf("%lld\n",ans[i]); }

Compilation message (stderr)

Main.cpp: In function 'void usaco(std::string)':
Main.cpp:5:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:5:66: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                                                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     scanf("%d%d",&n,&q);
      |     ~~~~~^~~~~~~~~~~~~~
Main.cpp:28:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
      |                          ~~~~~^~~~~~~~~~~~~~
Main.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         scanf("%lld",&x);
      |         ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...