# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
553171 | fcmalkcin | Gap (APIO16_gap) | C++17 | 0 ms | 0 KiB |
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 "gap.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
//#define endl "\n"
#define pb push_back
#define F(i,a,b) for(ll i=a;i<=b;i++)
const ll maxn=1e3+5e2+100;
const ll base=2e9;
const ll mod= 1e9+7 ;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
ll findGap(int t,int n)
{
if (t==1)
{
ll l=-1,h=1e18+1;
vector<ll> vt;
vector<ll> vt1;
ll mn,mx;
ll res=0;
for (int i=1; i<=(n+1)/2; i++)
{
MinMax(l+1,h-1,&mn,&mx);
vt.pb(mn);
vt1.pb(mx);
l=mn;
h=mx;
}
reverse(vt1.begin(),vt1.end());
for (auto to:vt1)
vt.pb(to);
for (int i=1; i<vt.size(); i++)
res=max(res,vt[i]-vt[i-1]);
return res;
}
else
{
ll mn,mx;
MinMax(0,1e18,&mn,&mx);
ll len=mx-mn;
ll pt=mx;
ll h=(len+n-1)/(n);
h--;
ll l=mn;
ll pre=base;
ll res=0;
while (1)
{
MinMax(l,l+h,&mn,&mx);
l+=(h+1);
if (mn!=-1)
{
res=max(res,mn-pre);
pre=mx;
if (mx==pt)
return ;
}
else
{
}
}
return res;
}
}
/*int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen("t.inp","r"))
{
freopen("test.inp","r",stdin);
freopen("test.out","w",stdout);
}
ll n;
cin>>n;
initialize(n);
for (int i=1;i<=n;i++)
{
}
}*/