Submission #378343

#TimeUsernameProblemLanguageResultExecution timeMemory
378343astoriaSnowball (JOI21_ho_t2)C++14
33 / 100
33 ms5284 KiB
#include "bits/stdc++.h" using namespace std; #define int long long const int N=1e5+5,Q=1e5+5; int n,q,x[N]; int pl[Q],pr[Q]; int reachL[N],reachR[N]; int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>n>>q; x[0]=-1e18-5e17; x[n+1]=1e18+5e17; for(int i=1; i<=n; i++) cin>>x[i]; vector<int> seg; for(int i=0; i<=n; i++) seg.push_back(x[i+1]-x[i]); pl[0]=0; pr[0]=0; int po=0; for(int i=1; i<=q; i++){ int v; cin>>v; po += v; pl[i]=min(pl[i-1],po); pr[i]=max(pr[i-1],po); } pl[q+1]=-4e18; pr[q+1]=4e18; reachL[1]=pl[q]; reachR[n]=pr[q]; for(int lo=2; lo<=q; lo++){ assert(pl[lo]==pl[lo-1] || pr[lo]==pr[lo-1]); } for(int i=1; i<n; i++){ int len = seg[i]; int lo=0,hi=q+1; //first pos where pl+pr >= len while(lo<hi){ int mid=(lo+hi)>>1; if(pr[mid]-pl[mid] >= len) hi=mid; else lo=mid+1; } //cout<<lo<<endl; if(lo==q+1){ reachR[i]=pr[q]; reachL[i+1]=pl[q]; continue; } //case where they never meet assert(lo!=0); //len is positive assert(pl[lo]==pl[lo-1] || pr[lo]==pr[lo-1] || lo==q+1); //this statement is triggered. How? Oh, Q+1 so not really //assert(pl[lo]!=pl[lo-1] || pr[lo]!=pr[lo-1]); if(pl[lo]!=pl[lo-1]){ reachR[i] = pr[lo-1]; reachL[i+1] = - (len - pr[lo-1]); //note reachL is negative //cout<<"LEFTCAUSE"<<i<<endl; } //left caused the ending else{ reachL[i+1] = pl[lo-1]; reachR[i] = len + pl[lo-1]; //reachL is negative so it's subtraction //cout<<"RIGHTCAUSE"<<i<<endl; } //right caused the ending } for(int i=1; i<=n; i++){ cout<<reachR[i]-reachL[i]<<'\n'; } /*for(int i=0; i<=q+1; i++){ cout<<pl[i]<<" "<<pr[i]<<endl; }*/ }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...