Rt,用的kdt,但是好像死循环了,应该是在建树的时候挂的
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#define int long long
using namespace std;
const int maxn = 1e5 + 1;
priority_queue <int> q;
int n, k, id, cnt = 2;
int lson[maxn], rson[maxn];
struct node{
int pos[2], maxx[2], minn[2];
bool operator<(const node&t) const{
pos[id] > t.pos[id];
}
}a[maxn];
int cheng(int x){return x * x;}
int dis(int x, int y){
return cheng(a[x].pos[1] - a[y].pos[1]) + cheng(a[x].pos[0] - a[y].pos[0]);
}
void push_up(int x, int y){
a[x].minn[0] = min(a[x].minn[0], a[y].minn[0]);
a[x].minn[1] = min(a[x].minn[1], a[y].minn[1]);
a[x].maxx[0] = max(a[x].maxx[0], a[y].maxx[0]);
a[x].maxx[1] = max(a[x].maxx[1], a[y].maxx[1]);
}
int build(int l, int r, int f){
if (l > r) return 0;
if (l == r){
for (int i = 0; i < 2; i++){
a[l].maxx[i] = a[l].minn[i] = a[l].pos[i];
}
return l;
}
id = f;
int mid = (l + r) >> 1;
nth_element(a + l, a + mid, a + r + 1);
for (int i = 0; i < 2; i++){
a[mid].maxx[i] = a[mid].minn[i] = a[mid].pos[i];
}
lson[mid] = build(l, mid - 1, !f);
if (lson[mid]) push_up(mid, lson[mid]);
rson[mid] = build(mid + 1, r, !f);
if (rson[mid]) push_up(mid, rson[mid]);
return mid;
}
void add(int x){
if (q.top() < x){
q.pop();
q.push(x);
}
}
void query(int now, int p){
if (now == 0) return;
if (now != p){
add(dis(now, p));
}
int Max = 0;
Max = max(max(cheng(a[p].pos[0] - a[now].maxx[0]) + cheng(a[p].pos[1] - a[now].maxx[1]), cheng(a[p].pos[0] - a[now].maxx[0]) + cheng(a[p].pos[1] - a[now].minn[1])), max(cheng(a[p].pos[0] - a[now].minn[0]) + cheng(a[p].pos[1] - a[now].maxx[1]), cheng(a[p].pos[0] - a[now].minn[0]) + cheng(a[p].pos[1] - a[now].minn[1])));
if (Max < q.top()) return;
if (p <= now){
query(rson[now], p);
query(lson[now], p);
}else{
query(lson[now], p);
query(rson[now], p);
}
}
signed main(){
scanf("%lld%lld", &n, &k);
k *= 2;
for (int i = 1; i <= k; i++){
q.push(0);
}
for (int i = 1; i <= n; i++){
scanf("%lld%lld", &a[i].pos[0], &a[i].pos[1]);
}
int root = build(1, n, 1);
for (int i = 1; i <= n; i++){
query(root, i);
}
printf("%lld", q.top());
return 0;
}