This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
interval check(long long l,long long r){
if(l+1==r)return {-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);
MinMax(mid,r-1, lt,rt);
return {*rr,*lt};
}
const long long inf=1e18;
long long *l,*r;
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});
if(N==2)return *r-*l;
while(true){
interval s=check(q.top().from,q.top().to);
if(s.from==-1 and s.to==-1)return q.top().to-q.top().from;
interval z=q.top();
q.pop();
if(s.from==-1)s.from=s.to;
if(s.to==-1)s.to=s.from;
if(z.from!=s.from)q.push({z.from,s.from});
if(s.from!=s.to)q.push(s);
if(s.to!=z.to)q.push({s.to,z.to});
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |