Submission #650206

#TimeUsernameProblemLanguageResultExecution timeMemory
650206milisavSnowball (JOI21_ho_t2)C++14
0 / 100
2 ms452 KiB
#include<bits/stdc++.h> #define maxn 200005 using namespace std; int n,q; long long x[maxn]; long long w[maxn]; long long a[maxn]; long long cnt[maxn]; bool sg(long long u,long long v) { if(u<=0 && v<=0) return true; if(u>=0 && v>=0) return true; return false; } int main() { scanf("%d %d",&n,&q); for(int i=0;i<n;i++) { scanf("%lld",&x[i]); } for(int i=0;i<q;i++) { scanf("%lld",&w[i]); } long long mi=0,ma=0; long long pos=w[0]; a[0]=0; a[1]=pos; mi=min(mi,pos); ma=max(ma,pos); int m=2; for(int i=1;i<q;i++) { pos+=w[i]; mi=min(mi,pos); ma=max(ma,pos); //cout<<i<<" "<<pos<<" "<<a[m-1]<<endl; if(sg(pos,a[m-1])) { if(abs(pos)>abs(a[m-1])) { a[m-1]=pos; } } else { //cout<<a[m-2]<<endl; if(abs(pos)>abs(a[m-2])) { //cout<<"inc"<<endl; a[m]=pos; m++; } } } //for(int i=0;i<m;i++) cout<<a[i]<<" "; //cout<<endl; cnt[0]-=mi; cnt[n-1]+=ma; for(int i=1;i<n;i++) { long long len=x[i]-x[i-1]; int l=1; int r=m-1; if(abs(a[r])+abs(a[r-1])<len) { if(a[r]<=0) { cnt[i]-=a[r]; cnt[i-1]+=a[r-1]; } else { cnt[i-1]+=a[r]; cnt[i]-=a[r-1]; } continue; } while(l<r) { int md=(l+r)/2; if(abs(a[md])+abs(a[md-1])<len) l=md+1; else r=md; } //cout<<i<<" "<<x[i]<<" "<<x[i-1]<<" "<<l<<" "<<a[l]<<" "<<a[l-1]<<" "<<len<<endl; if(a[l-1]<=0) { cnt[i]-=a[l-1]; cnt[i-1]+=(len+a[l-1]); } else { cnt[i-1]+=a[l-1]; cnt[i]+=(len-a[l-1]); } } for(int i=0;i<n;i++) { printf("%lld\n",cnt[i]); } return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     scanf("%d %d",&n,&q);
      |     ~~~~~^~~~~~~~~~~~~~~
Main.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         scanf("%lld",&x[i]);
      |         ~~~~~^~~~~~~~~~~~~~
Main.cpp:20:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         scanf("%lld",&w[i]);
      |         ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...