Submission #1104670

#TimeUsernameProblemLanguageResultExecution timeMemory
1104670alexander707070Shortcut (IOI16_shortcut)C++14
71 / 100
2070 ms19384 KiB
#include<bits/stdc++.h> #define MAXN 100007 using namespace std; const long long inf=1e15; int n,len[MAXN],d[MAXN],c; long long pos[MAXN]; int where[MAXN],cnt; pair<long long,int> mp[MAXN]; struct rect{ long long minx,maxx; long long miny,maxy; inline friend rect operator + (rect fr,rect sc){ return {max(fr.minx,sc.minx),min(fr.maxx,sc.maxx),max(fr.miny,sc.miny),min(fr.maxy,sc.maxy)}; } }; struct ST{ struct node{ long long mins,maxs; }; node tree[4*MAXN]; void init(){ for(int i=0;i<=4*n;i++){ tree[i].mins=inf; tree[i].maxs=-inf; } } void update(int v,int l,int r,int pos,long long val){ if(l==r){ tree[v].mins=min(tree[v].mins,val); tree[v].maxs=max(tree[v].maxs,val); }else{ int tt=(l+r)/2; if(pos<=tt){ update(2*v,l,tt,pos,val); }else{ update(2*v+1,tt+1,r,pos,val); } tree[v].mins=min(tree[2*v].mins,tree[2*v+1].mins); tree[v].maxs=max(tree[2*v].maxs,tree[2*v+1].maxs); } } pair<long long,long long> combine(pair<long long,long long> fr,pair<long long,long long> sc){ return {min(fr.first,sc.first),max(fr.second,sc.second)}; } pair<long long,long long> getinfo(int v,int l,int r,int ll,int rr){ if(ll>rr)return {inf,-inf}; if(l==ll and r==rr)return {tree[v].mins,tree[v].maxs}; int tt=(l+r)/2; return combine( getinfo(2*v,l,tt,ll,min(tt,rr)) , getinfo(2*v+1,tt+1,r,max(tt+1,ll),rr) ); } }segx,segy; int bin(long long x){ int l=0,r=n+1,tt; while(l+1<r){ tt=(l+r)/2; if(x<=mp[tt].first){ r=tt; }else{ l=tt; } } if(r==n+1)return cnt+1; return where[mp[r].second]; } bool ok(long long fix){ rect s={-inf,inf,-inf,inf},curr; segx.init(); segy.init(); for(int i=n;i>=1;i--){ int from=bin(fix+pos[i]-d[i]+1); pair<long long,long long> s1=segx.getinfo(1,1,cnt,from,cnt); pair<long long,long long> s2=segy.getinfo(1,1,cnt,from,cnt); curr={pos[i]+d[i]+s1.second-fix+c , pos[i]-d[i]+s2.first+fix-c , -pos[i]+d[i]+s1.second-fix+c , -pos[i]-d[i]+s2.first+fix-c}; s=s+curr; segx.update(1,1,cnt,where[i],pos[i]+d[i]); segy.update(1,1,cnt,where[i],pos[i]-d[i]); } for(int i=1;i<=n;i++){ int l=i+1,r=n+1,tt; while(l+1<r){ tt=(l+r)/2; if(pos[tt]<=min(s.maxx-pos[i],s.maxy+pos[i])){ l=tt; }else{ r=tt; } } if(pos[l]-pos[i]>=s.miny and pos[l]-pos[i]<=s.maxy and pos[l]+pos[i]>=s.minx and pos[l]+pos[i]<=s.maxx)return true; } return false; } long long find_shortcut(int N,vector<int> L,vector<int> D, int C){ n=N; c=C; for(int i=1;i<=n-1;i++){ len[i]=L[i-1]; } for(int i=2;i<=n;i++){ pos[i]=pos[i-1]+len[i-1]; } for(int i=1;i<=n;i++){ d[i]=D[i-1]; } for(int i=1;i<=n;i++)mp[i]={pos[i]+d[i],i}; sort(mp+1,mp+n+1); for(int i=1;i<=n;i++){ if(i==1 or mp[i].first!=mp[i-1].first)cnt++; where[mp[i].second]=cnt; } long long l=0,r=inf,tt; while(l+1<r){ tt=(l+r)/2; if(ok(tt)){ r=tt; }else{ l=tt; } } return r; } /*int main(){ //cout<<find_shortcut(9, {10, 10, 10, 10, 10, 10, 10, 10},{20, 0, 30, 0, 0, 40, 0, 40, 0}, 30)<<"\n"; //cout<<find_shortcut(4, {2, 2, 2},{1, 10, 10, 1}, 1)<<"\n"; //cout<<find_shortcut(3, {1, 1},{1, 1, 1}, 3)<<"\n"; return 0; }*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...