제출 #1092476

#제출 시각아이디문제언어결과실행 시간메모리
1092476alexander707070Gap (APIO16_gap)C++14
19.19 / 100
76 ms8896 KiB
#include<bits/stdc++.h> #include "gap.h" #define MAXN 600007 using namespace std; struct interval{ long long from,to; inline friend bool operator < (interval fr,interval sc){ return fr.to-fr.from<sc.to-sc.from; } }; priority_queue<interval> q,qq; pair<interval,interval> check(long long l,long long r){ if(l+1==r)return {{-1,-1},{-1,-1}}; long long mid=(l+r)/2; long long *ll,*rr,*lt,*rt; ll=new long long(); rr=new long long(); lt=new long long(); rt=new long long(); MinMax(l+1,mid, ll,rr); if(mid+1<=r-1)MinMax(mid+1,r-1, lt,rt); else{ *lt=-1; *rt=-1; } return {{*ll,*rr},{*lt,*rt}}; } const long long inf=1e18; long long *l,*r; bool better(){ if(qq.empty())return true; return q.top().to-q.top().from > qq.top().to-qq.top().from; } long long findGap(int T, int N){ while(!q.empty())q.pop(); l=new long long(); r=new long long(); MinMax(1, inf, l,r); q.push({*l,*r}); while(better()){ pair<interval,interval> s=check(q.top().from,q.top().to); if(s.first.from==-1 and s.second.to==-1)return q.top().to-q.top().from; interval z=q.top(); q.pop(); if(s.second.from==-1)swap(s.first,s.second); if(s.first.from==-1){ qq.push({z.from,s.second.from}); qq.push({s.second.to,z.to}); if(s.second.from!=s.second.to)q.push({s.second.from,s.second.to}); }else{ qq.push({z.from,s.first.from}); qq.push({s.second.to,z.to}); qq.push({s.first.to,s.second.from}); if(s.first.from!=s.first.to)q.push({s.first.from,s.second.from}); if(s.second.from!=s.second.to)q.push({s.second.from,s.second.to}); } } return qq.top().to-qq.top().from; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...