Submission #1110848

#TimeUsernameProblemLanguageResultExecution timeMemory
1110848imarnSnowball (JOI21_ho_t2)C++14
33 / 100
809 ms16712 KiB
#include<bits/stdc++.h> #define ll long long #define pii pair<int,int> #define pll pair<ll,ll> #define plx pair<ll,int> #define f first #define s second #define pb push_back #define all(x) x.begin(),x.end() #define vi vector<int> #define vvi vector<vi> #define pp pair<ll,int> #define ub(x,i) upper_bound(all(x),i)-x.begin() using namespace std; int main(){ ios_base::sync_with_stdio(0);cin.tie(0); int n,q;cin>>n>>q; ll x[n+1];for(int i=1;i<=n;i++)cin>>x[i]; vector<pll> w(q+1),ww(q+1);w[0]={0,0};for(int i=1;i<=q;i++)cin>>w[i].f,w[i].f+=w[i-1].f,w[i].s=i,ww[i]={-w[i].f,w[i].s}; ll t=2e16,t2=2e16; sort(all(w)); sort(all(ww)); ll l[n+1],r[n+1]; for(int i=1;i<=n;i++){ l[i]=x[i]+w[0].f,r[i]=x[i]+w[q].f; if(i>1)l[i]=max(l[i],x[i-1]); if(i<n)r[i]=min(r[i],x[i+1]); } for(int i=q;i>=0;i--){ t=min(t,w[i].s); w[i].s=min(t,w[i].s); t2=min(t2,ww[i].s); ww[i].s=min(t2,ww[i].s); } for(int i=2;i<=n;i++){ if(r[i-1]<=l[i])continue; ll tl=l[i],tr=r[i-1]+1; while(tl<tr){ ll md=(tl+tr)>>1;ll lf,rg; lf = lower_bound(all(w),make_pair(md-x[i-1],-1ll))->s; rg=lower_bound(all(ww),make_pair(x[i]-md+1,-1ll))->s; if(lf<rg)tl=md+1; else tr=md; }r[i-1]=tl-1; l[i]=tl-1; } for(int i=1;i<=n;i++){ cout<<r[i]-l[i]<<'\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...