이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |