Language: C++

#include <iostream>
#include <vector>

using namespace std;

struct ioi
{
	int x,i,type;
	ioi(){}
	ioi(int a,int b,int c){x=a,i=b,type=c;}
}p[20010];

int n,x[10010],y[10010],bin[20010],last[10010],counter[20010],sz,in_st[20010],co,order[200010],al[200010],st[200010],top;
vector<int> a[200010],b[200010];

void find_max(int p,int l,int r)
{
	sz=max(sz,p);
	if (l==r)
	{
		in_st[l]=p;
		return;
	}
	find_max(p*2,l,(l+r)/2);
	find_max(p*2+1,(l+r)/2+1,r);
}

void build(int p,int l,int r)
{
	if (l==r)
	{
		a[p].push_back(sz+counter[l]);
		//cout << p << " " << sz+counter[l] << "\n";
		return;
	}
	build(p*2,l,(l+r)/2);
	build(p*2+1,(l+r)/2+1,r);
	a[p].push_back(p*2);
	a[p].push_back(p*2+1);
	//cout << p << " " << p*2 << "\n";
	//cout << p << " " << p*2+1 << "\n";
}

void add_edge(int p,int l,int r,int u,int A,int B)
{
	if (r<A or l>B) return;
	if (l>=A and r<=B)
	{
		a[u].push_back(p);
		//cout << u << " " << p << "\n";
		//if (u==15) cout << l << " " << r << " ";
		return;
	}
	add_edge(p*2,l,(l+r)/2,u,A,B);
	add_edge(p*2+1,(l+r)/2+1,r,u,A,B);
}

void dfs(int u)
{
	al[u]=1;
	for (int i=0;i<a[u].size();i++)
		if (!al[a[u][i]]) dfs(a[u][i]);
	st[++top]=u;
}

void kora(int u,int root)
{
	//cout << u << " ";
	al[u]=root;
	for (int i=0;i<b[u].size();i++)
		if (!al[b[u][i]]) kora(b[u][i],root);
}

void korasaju()
{
	co=top=0;
	for (int i=1;i<=sz+2*n;i++)	
		al[i]=0;
	for (int i=1;i<=sz+2*n;i++)
		if (!al[i]) dfs(i);
	for (int i=1;i<=sz+2*n;i++)
		al[i]=0;
	for (int i=1;i<=sz+2*n;i++)
		b[i].clear();
	for (int i=1;i<=sz+2*n;i++)
		for (int j=0;j<a[i].size();j++)
			b[a[i][j]].push_back(i);
	while (top)
	{
		if (!al[st[top]]) kora(st[top],st[top]);
		top--;
	}

}	

bool check(int dis)
{
	dis--;
	for (int i=1;i<=sz+2*n;i++)
		a[i].clear();
	build(1,1,2*n);
	for (int i=1;i<=2*n;i++)
	{
		int L=lower_bound(bin+1,bin+2*n+1,bin[i]-dis)-bin,R=(upper_bound(bin+1,bin+2*n+1,bin[i]+dis)-bin)-1;
		//cout << i << " " << L << " " << R << "\n";
		if (i-1>=L) add_edge(1,1,2*n,i+sz,L,i-1);
		if (i+1<=R) add_edge(1,1,2*n,i+sz,i+1,R);
	}
	korasaju();
	for (int i=1;i<=2*n;i++)
		if (al[i+sz]==al[counter[i]+sz]) return false;
	return true;
}

int main()
{
	//freopen("input.txt","r",stdin);
	cin >> n;
	for (int i=1;i<=n;i++)
	{
		cin >> x[i] >> y[i];
		p[i]=ioi(x[i],i,0);
		p[i+n]=ioi(y[i],i,1);
	}
	sort(p+1,p+2*n+1,[](ioi a,ioi b){
		return (a.x<b.x);
	});
	for (int i=1;i<=2*n;i++)
	{
		bin[i]=p[i].x;
		if (last[p[i].i]) counter[i]=last[p[i].i],counter[last[p[i].i]]=i;
		else last[p[i].i]=i; 
	}
	find_max(1,1,2*n);
	int l=0,r=1e9+10,res=0;
	//cout << check(4);
	while (l<=r)
	{
		int m=(l+r)/2;
		if (check(m)) res=m,l=m+1;
		else r=m-1;
	}
	cout << res;
}

Compiler output:
a.cc: In function 'bool check(int)':
a.cc:104:70: error: 'upper_bound' was not declared in this scope
  104 |                 int L=lower_bound(bin+1,bin+2*n+1,bin[i]-dis)-bin,R=(upper_bound(bin+1,bin+2*n+1,bin[i]+dis)-bin)-1;
      |                                                                      ^~~~~~~~~~~
a.cc: In function 'int main()':
a.cc:125:9: error: 'sort' was not declared in this scope; did you mean 'short'?
  125 |         sort(p+1,p+2*n+1,[](ioi a,ioi b){
      |         ^~~~
      |         short