/*
考虑暴力 可以n ^ 2枚举点对 然后用一个容量为2k的小根堆来维护第k大
kd-tree呢就是来将这个暴力优化, 每次先找远的并且最远距离不如堆顶的话就不继续找下去
貌似挺难构造数据卡的
*/ #include<iostream>
#include<queue>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define M 100010
#define ll long long
#define inf 1000000000000000ll
#define sqr(x) 1ll * (x)* (x)
using namespace std;
int read() {
int nm = , f = ;
char c = getchar();
for(; !isdigit(c); c = getchar()) if(c == '-') f = -;
for(; isdigit(c); c = getchar()) nm = nm * + c - '';
return nm * f;
}
int n, k, q, root, lc[M], rc[M];
ll minn[M][], maxx[M][];
struct Note {
ll d[];
bool operator < (const Note &b) const {
return d[q] != b.d[q] ? d[q] < b.d[q] : d[q^] < b.d[q ^ ];
}
} tmp, ver[M]; priority_queue<ll, vector<ll>, greater<ll> >que; void pushup(int x) {
for(int i = ; i <= ; i++) {
minn[x][i] = maxx[x][i] = ver[x].d[i];
minn[x][i] = min(minn[x][i], min(minn[lc[x]][i], minn[rc[x]][i]));
maxx[x][i] = max(maxx[x][i], max(maxx[lc[x]][i], maxx[rc[x]][i]));
}
} int build(int l, int r, int kx) {
if(l > r) return ;
int mid = (l + r) >> ;
q = kx;
nth_element(ver + l, ver + mid, ver + r + );
lc[mid] = build(l, mid - , kx ^ );
rc[mid] = build(mid + , r, kx ^ );
pushup(mid);
return mid;
} ll get(int x) {
if(!x) return ;
ll rt = ;
for(int i = ; i <= ; i++) rt += max(sqr(maxx[x][i] - tmp.d[i]), sqr(minn[x][i] - tmp.d[i]));
return rt;
} ll calc(Note a, Note b) {
return sqr(a.d[] - b.d[]) + sqr(a.d[]-b.d[]);
} void query(int x) {
if(!x) return;
ll dl = get(lc[x]), dr = get(rc[x]), d = calc(tmp, ver[x]);
if(d > que.top()) que.pop(), que.push(d);
if(dl > dr) {
if(dl > que.top()) query(lc[x]);
if(dr > que.top()) query(rc[x]);
} else {
if(dr > que.top()) query(rc[x]);
if(dl > que.top()) query(lc[x]);
}
}
int main() {
n = read(), k = read();
for(int i = ; i <= n; i++) ver[i].d[] = read(), ver[i].d[] = read();
for(int i = ; i <= ; i++) minn[][i] = inf, maxx[][i] = -inf;
root = build(, n, );
for(int i = ; i <= * k; i++) que.push();
for(int i = ; i <= n; i++) tmp = ver[i],query(root);
cout << que.top();
return ;
}

「CQOI2016」K 远点对的更多相关文章

  1. LibreOJ2043 - 「CQOI2016」K 远点对

    Portal Description 给出平面上的\(n(n\leq10^5)\)个整点,求在欧几里得距离下第\(k\)远的点对之间的距离. Solution k-d树+堆. 用小根堆维护当前找到的第 ...

  2. loj2043 「CQOI2016」K 远点对

    k-d tree 裸题------ #include <algorithm> #include <iostream> #include <cstdio> using ...

  3. LibreOJ2044 - 「CQOI2016」手机号码

    Portal Description 给出两个十一位数\(L,R\),求\([L,R]\)内所有满足以下两个条件的数的个数. 出现至少\(3\)个相邻的相同数字: 不能同时出现\(4\)和\(8\). ...

  4. LoibreOJ 2042. 「CQOI2016」不同的最小割 最小割树 Gomory-Hu tree

    2042. 「CQOI2016」不同的最小割 内存限制:256 MiB时间限制:1000 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: 匿名 提交提交记录统计讨论测试数据   题目描述 ...

  5. loj #2044. 「CQOI2016」手机号码

    #2044. 「CQOI2016」手机号码 内存限制:256 MiB时间限制:1000 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: 匿名 提交提交记录统计讨论测试数据   题目描述 ...

  6. LibreOJ2045 - 「CQOI2016」密钥破解

    Portal Description 给出三个正整数\(e,N,c(\leq2^{62})\).已知\(N\)能表示成\(p\cdot q\)的形式,其中\(p,q\)为质数.计算\(r=(p-1)( ...

  7. LibreOJ2042 - 「CQOI2016」不同的最小割

    Portal Description 给出一个给出一个\(n(n\leq850)\)个点\(m(m\leq8500)\)条边的无向图.定义\(cut(s,t)\)等于\(s,t\)的最小割的容量,求在 ...

  8. 「CQOI2016」不同的最小割

    「CQOI2016」不同的最小割 传送门 建出最小割树,把每一个点对的最小割抠出来 \(\text{unique}\) 一下就好了. 参考代码: #include <algorithm> ...

  9. 「ZJOI2013」K大数查询

    「ZJOI2013」K大数查询 传送门 整体二分,修改的时候用线段树代替树状数组即可. 参考代码: #include <cstdio> #define rg register #defin ...

随机推荐

  1. Foundation--结构体

    一,NSRange typedef struct _NSRange { NSUInteger location; NSUInteger length; }NSRange; 这个结构体用来表示事物的一个 ...

  2. ftp添加虚拟用户的实例

    本文主要讲解添加一个ftp虚拟用户的流程,接上文 https://www.cnblogs.com/tssc/p/9582780.html ========= 完美的分割线 ======== 1.修改授 ...

  3. Samsung_tiny4412(驱动笔记07)----spinlock,semaphore,atomic,mutex,completion,interrupt

    /*********************************************************************************** * * spinlock,se ...

  4. Springboot中的连接池

    pom.xml <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-ja ...

  5. js 获取客户端mac地址

    js 获取客户端mac地址 javascript获取客户端网卡MAC地址和IP地址和计算机名 nodesj如何获得客户端的mac地址呢? 浏览器获取MAC地址 不限浏览器的mac地址取得的几种办法 I ...

  6. jQuery事件绑定汇总(包括一些无法获取事件的问题)

    ★ $(document).on('click', 'button[name=closeLayerOut2]', function () { ...... }); $(document).on('cl ...

  7. setTimeout设置为0的作用

    调用方式:iTimerID = window.setTimeout(vCode, iMilliSeconds [, sLanguage])功能:Evaluates an expression afte ...

  8. asp.net && javascript MD5加密

    /* * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message * Digest Algorithm, as d ...

  9. 用vbs打开文件

    set ws=createobject("wscript.shell")ws.run"打开文件所使用的程序+空格+程序路径",x,ture Run方法有三个参数 ...

  10. 【转】每天一个linux命令(58):telnet命令

    原文网址:http://www.cnblogs.com/peida/archive/2013/03/13/2956992.html telnet命令通常用来远程登录.telnet程序是基于TELNET ...