nth_element相当于快排的split/choose pivot过程
2D 最近
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
const int INF=0x3f3f3f3f;
const int maxn=1e5+50;
typedef long long ll;
using namespace std;
int cmpNo;
struct Node{
int x[2],l,r,id;
bool operator <(const Node &b)const{
return x[cmpNo]<b.x[cmpNo];
}
};
ll calDis(Node &l,Node &r){
ll dx=l.x[0]-r.x[0],dy=l.x[1]-r.x[1];
return dx*dx+dy*dy;
}
Node p[maxn];
int Build(int l,int r,int d){
if(l>r)return 0;
cmpNo=d;
int mid=l+r>>1;
nth_element(p+l,p+mid,p+r+1);
p[mid].l=Build(l,mid-1,1-d);
p[mid].r=Build(mid+1,r,1-d);
return mid;
}
ll ansDist;
int<