Language: C++

#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
//#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PI;
typedef pair< PI, int> PII;
#define pb push_back
#define Key_value ch[ch[root][1]][0]
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define MS(x,y) memset(x,y,sizeof(x))
const double eps = 1e-6;
const double pi = acos (-1.0);
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int M = 300005;

const int maxn = 1e5 + 10;

int n,pn,cnt,b[maxn],fa[maxn];
struct Point{
    int x,y;
    int id;
    bool operator<(const Point& rhs) const
    {
        return x < rhs.x || (x == rhs.x && y < rhs.y);
    }
} p[maxn];
struct Edge{
    int u,v;
    LL d;
    bool operator<(const Edge& rhs) const
    {
        return d < rhs.d;
    }
} e[maxn<<2];
void addEdge(int u,int v,LL d)
{
    e[cnt].u = u;
    e[cnt].v = v;
    e[cnt++].d = d;
}
struct Bit{
    int mn,pos;
    void init()
    {
        mn = INF;
        pos = -1;
    }
} bit[maxn];
inline int lowbit(int x)
{
    return x&-x;
}
void update(int x,int mn,int pos)
{
    for(int i=x;i>0;i-=lowbit(i))
    {
        if(bit[i].mn > mn)
        {
            bit[i].mn = mn;
            bit[i].pos = pos;
        }
    }
}
int query(int x)
{
    int mn = INF,pos = -1;
    for(int i = x;i<=pn;i+=lowbit(i))
    {
        if(bit[i].mn < mn)
        {
            mn = bit[i].mn;
            pos = bit[i].pos;
        }
    }
    return pos;
}
int find(int x)
{
    return fa[x] == x?x:fa[x] = find(fa[x]);
}

LL solve()
{
    cnt = 0;
    for(int dir = 0;dir<4;++dir)
    {
        if(dir&1) for(int i=0;i<n;++i) swap(p[i].x,p[i].y);
        if(dir == 2) for(int i=0;i<n;++i) p[i].x = -p[i].x;
        sort(p,p+n);
        for(int i=0;i<n;++i) b[i] = p[i].y - p[i].x;
        sort(b,b+n);
        pn = unique(b,b+n) - b;
        for(int i=1;i<=pn;++i) bit[i].init();
        for(int i=n-1;i>=0;--i)
        {
            int pos = lower_bound(b,b+pn,p[i].y - p[i].x) - b + 1;
            int po = query(pos);
            if(po != -1)
                addEdge(p[i].id,p[po].id,min(abs(p[i].x-p[po].x) , abs(p[po].y-p[i].y)));
            update(pos,p[i].y + p[i].x,i);
        }
    }
    LL res = 0;
    for(int i=0;i<n;++i) fa[i] = i;
    sort(e,e+cnt);
    for(int i=0;i<cnt;++i)
    {
        int u = find(e[i].u),v = find(e[i].v);
        if(u != v)
        {
            fa[u] = v;
            res += e[i].d;
        }
    }
    return res;
}
int main()
{
    cin >> n;
    for(int i=0;i<n;++i)
    {
        scanf("%d %d",&p[i].x,&p[i].y);
        p[i].id = i;
    }
    LL ans = solve();
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'LL solve()':
a.cc:96:9: error: 'sort' was not declared in this scope; did you mean 'sqrt'?
   96 |         sort(p,p+n);
      |         ^~~~
      |         sqrt
a.cc:99:14: error: 'unique' was not declared in this scope
   99 |         pn = unique(b,b+n) - b;
      |              ^~~~~~
a.cc:112:5: error: 'sort' was not declared in this scope; did you mean 'sqrt'?
  112 |     sort(e,e+cnt);
      |     ^~~~
      |     sqrt