P12541 code
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "hack.h"
#else
int hack();
long long collisions(std::vector<long long> x);
#endif
typedef long long ll;
const ll Mx=1e18;
bool check(int l,int r) {
for(int i=1e9;i;i=i/10) while(2ll*(l+(i-1))<=r) l=l+i;
int len=r-l+1,bk=sqrt(len);
while(bk*bk>len) --bk;
while((bk+1)*(bk+1)<=len) ++bk;
vector<ll> tmp;tmp.clear();
for(int i=0;i<bk;++i) tmp.push_back(Mx-i);
for(int i=0,rit=r;i<bk;++i,rit=rit-bk) tmp.push_back(Mx-rit);
if(collisions(tmp)) return true;
if(r-bk*bk>=l) return check(l,r-bk*bk);
return false;
}
int pw(int x,int y) {
int rs=1;
while(y--) rs=rs*x;
return rs;
}
int hack(){
int l=5e8+1,r=1e9,mid,res;
while(l<=r) {
mid=(l+r)>>1;
if(check(l,mid)) res=mid,r=mid-1;
else l=mid+1;
}
int p=res,rect=res;
for(int i=2;i*i<=p;++i) {
if(p%i) continue;
int l1=0,r1=0,mid1,res1;
while(!(p%i)) p=p/i,++r1;
int R=r1;
while(l1<=r1) {
mid1=(l1+r1)>>1;
if(check(rect/pw(i,R)*pw(i,mid1),rect/pw(i,R)*pw(i,mid1))) res1=mid1,r1=mid1-1;
else l1=mid1+1;
}
rect=rect/pw(i,R)*pw(i,res1);
}
if(p>1) if(check(rect/p,rect/p)) return rect/p;
return rect;
}