이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "gap.h"
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e18;
pair<int,int> qry(int le, int ri)
{
pair<int,int> aux;
MinMax(le,ri,&aux.first,&aux.second);
return aux;
}
long long bigsolve(int N)
{
int rez=1;
pair<int,int> tot = qry(0,INF);
int cur=tot.first;
while(tot.second - cur > rez)
{
pair<int,int> aux = qry(cur+1,cur+rez);
if(aux.first!=-1)
{
cur = aux.second;
continue;
}
int c=rez;
while(1)
{
c=(c+1)*2;
aux = qry(cur+1,cur+c);
if(aux.first!=-1)
{
rez = max(rez, aux.first - cur);
cur = aux.second;
break;
}
}
}
return rez;
}
int smallsolve(int N)
{
pair<int,int> tot = qry(0,INF);
int le=tot.first,ri=tot.second,rez=1,pozle=1,pozri=N;
while(ri-le > rez)
{
if(pozle+1>=pozri)
{
rez = max(rez, ri-le);
break;
}
pair<int,int> aux = qry(le+1,ri-1);
rez = max(rez, aux.first-le);
rez = max(rez, ri-aux.second);
le = aux.first;
ri = aux.second;
pozle++;
pozri--;
}
return rez;
}
long long findGap(int32_t T, int32_t N)
{
if(T==1 || N<=100) return smallsolve(N);
return bigsolve(N);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |