Submission #1104643

#TimeUsernameProblemLanguageResultExecution timeMemory
1104643alexander707070Shortcut (IOI16_shortcut)C++14
71 / 100
2062 ms147016 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]; 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{ int l,r; long long mins,maxs; }; node tree[60*MAXN]; int num; void init(){ for(int i=0;i<=60*n;i++){ tree[i].mins=inf; tree[i].maxs=-inf; tree[i].l=tree[i].r=0; } num=1; } void addnode(){ num++; } void update(int v,long long l,long long r,long long pos,long long val){ if(l==r){ tree[v].mins=min(tree[v].mins,val); tree[v].maxs=max(tree[v].maxs,val); }else{ long long tt=(l+r)/2; if(pos<=tt){ if(tree[v].l==0){ addnode(); tree[v].l=num; } update(tree[v].l,l,tt,pos,val); }else{ if(tree[v].r==0){ addnode(); tree[v].r=num; } update(tree[v].r,tt+1,r,pos,val); } tree[v].mins=min(tree[tree[v].l].mins,tree[tree[v].r].mins); tree[v].maxs=max(tree[tree[v].l].maxs,tree[tree[v].r].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,long long l,long long r,long long ll,long long rr){ if(ll>rr or v==0)return {inf,-inf}; if(l==ll and r==rr)return {tree[v].mins,tree[v].maxs}; long long tt=(l+r)/2; return combine( getinfo(tree[v].l,l,tt,ll,min(tt,rr)) , getinfo(tree[v].r,tt+1,r,max(tt+1,ll),rr) ); } }segx,segy; bool ok(long long fix){ rect s={-inf,inf,-inf,inf},curr; segx.init(); segy.init(); for(int i=n;i>=1;i--){ pair<long long,long long> s1=segx.getinfo(1,1,inf,max(fix+pos[i]-d[i]+1,1LL),inf); pair<long long,long long> s2=segy.getinfo(1,1,inf,max(fix+pos[i]-d[i]+1,1LL),inf); 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,inf,pos[i]+d[i],pos[i]+d[i]); segy.update(1,1,inf,pos[i]+d[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]; } 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...