Submission #756354

#TimeUsernameProblemLanguageResultExecution timeMemory
7563541075508020060209tcSnowball (JOI21_ho_t2)C++14
100 / 100
557 ms18468 KiB
#include<bits/stdc++.h> using namespace std; #define int long long int n;int Q; int xar[200005]; int adar[200005]; int psad[200005]; int mnad[200005]; int mxad[200005]; int lans[200005]; int rans[200005]; signed main(){ cin>>n>>Q; for(int i=1;i<=n;i++){ cin>>xar[i]; } for(int i=1;i<=Q;i++){ cin>>adar[i]; psad[i]=adar[i]+psad[i-1]; mnad[i]=min(mnad[i-1],psad[i]); mxad[i]=max(mxad[i-1],psad[i]); } lans[1]=xar[1]+mnad[Q]; rans[n]=xar[n]+mxad[Q]; for(int i=1;i<=n-1;i++){ int l=0;int r=Q; while(l<r){ int mi=l+(r-l+1)/2; if( xar[i]+mxad[mi]<=xar[i+1]+mnad[mi] ){ l=mi; }else{ r=mi-1; } } if( ((l==Q)||(l!=Q&&adar[l+1]<0)) ){ rans[i]=xar[i]+mxad[l]; }else{ rans[i]=xar[i+1]+mnad[l]; } } for(int i=n;i>=2;i--){ int l=0;int r=Q; while(l<r){ int mi=l+(r-l+1)/2; if( xar[i]+mnad[mi]>=xar[i-1]+mxad[mi] ){ l=mi; }else{ r=mi-1; } } if( (l==Q||adar[l+1]>0) ){ lans[i]=xar[i]+mnad[l]; }else{ lans[i]=xar[i-1]+mxad[l]; } } for(int i=1;i<=n;i++){ cout<<rans[i]-lans[i]<<endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...