/*
考虑暴力 可以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. ZooKeeper 集群环境搭建 (本机3个节点)

    --------------------------------------------------------1.建立目录server1server1/dataDirserver1/dataLogD ...

  2. 大龄码农那些事——也谈996.ICU

    1.背景 近期Github突然有一个开源项目火了,叫“996.icu”,开源地址:https://github.com/996icu/996.ICU ,目前star的人数截止我写这篇博文时已经高达17 ...

  3. SendTo MD5 - imsoft.cnblogs

    SendTo MD5 is a small application that allows you to calculate and compare MD5 checksums of files an ...

  4. C++ 拷贝构造函数和赋值构造函数

    转自:http://blog.chinaunix.net/uid-28662931-id-3496326.html 一.拷贝构造函数 int main(int argc, char * argv[]) ...

  5. Lists.transform的使用

    转自:https://blog.csdn.net/weixin_42201566/article/details/81513769 Lists.transform:能够轻松的从一种类型的list转换为 ...

  6. js操作链接url

    使用js对当前的URL进行操作,可以使用内置对象window.location: window.location有以下属性: window.location.href:取得当前地址栏中的完整URL,可 ...

  7. Open-sourcing sso, the way we secure services at BuzzFeed

    文章来源: https://tech.buzzfeed.com/unleashing-the-a6a1a5da39d6 说明: 设计有好多地方值得借鉴,粘贴过来的排版不好 Today we are o ...

  8. SQL Server获取指定行的数据

    SQL Server获取指定行(如第二行)的数据   --SQL Server获取指定行(如第二行)的数据-- --法一(对象法)-- select * from ( select * , numbe ...

  9. 【MVC】VS常用技巧

    1,在VS2010中,选中指定的代码段,可以拖拽到工具箱中,形成标签,以后还想书写类似的代码,双击鼠标即可. 2,在VS2012中,可以在注释上标注//TODO:我是注释 这样,注释就会出现在任务列表 ...

  10. Collection与Collections,Array与Arrays的区别

    Collection 和 Collections的区别 Collection 在Java.util下的一个接口,它是各种集合结构的父接口.继承与他的接口主要有Set 和List. Collection ...