「CQOI2016」K 远点对
/*
考虑暴力 可以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 远点对的更多相关文章
- LibreOJ2043 - 「CQOI2016」K 远点对
Portal Description 给出平面上的\(n(n\leq10^5)\)个整点,求在欧几里得距离下第\(k\)远的点对之间的距离. Solution k-d树+堆. 用小根堆维护当前找到的第 ...
- loj2043 「CQOI2016」K 远点对
k-d tree 裸题------ #include <algorithm> #include <iostream> #include <cstdio> using ...
- LibreOJ2044 - 「CQOI2016」手机号码
Portal Description 给出两个十一位数\(L,R\),求\([L,R]\)内所有满足以下两个条件的数的个数. 出现至少\(3\)个相邻的相同数字: 不能同时出现\(4\)和\(8\). ...
- LoibreOJ 2042. 「CQOI2016」不同的最小割 最小割树 Gomory-Hu tree
2042. 「CQOI2016」不同的最小割 内存限制:256 MiB时间限制:1000 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: 匿名 提交提交记录统计讨论测试数据 题目描述 ...
- loj #2044. 「CQOI2016」手机号码
#2044. 「CQOI2016」手机号码 内存限制:256 MiB时间限制:1000 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: 匿名 提交提交记录统计讨论测试数据 题目描述 ...
- LibreOJ2045 - 「CQOI2016」密钥破解
Portal Description 给出三个正整数\(e,N,c(\leq2^{62})\).已知\(N\)能表示成\(p\cdot q\)的形式,其中\(p,q\)为质数.计算\(r=(p-1)( ...
- LibreOJ2042 - 「CQOI2016」不同的最小割
Portal Description 给出一个给出一个\(n(n\leq850)\)个点\(m(m\leq8500)\)条边的无向图.定义\(cut(s,t)\)等于\(s,t\)的最小割的容量,求在 ...
- 「CQOI2016」不同的最小割
「CQOI2016」不同的最小割 传送门 建出最小割树,把每一个点对的最小割抠出来 \(\text{unique}\) 一下就好了. 参考代码: #include <algorithm> ...
- 「ZJOI2013」K大数查询
「ZJOI2013」K大数查询 传送门 整体二分,修改的时候用线段树代替树状数组即可. 参考代码: #include <cstdio> #define rg register #defin ...
随机推荐
- 解析XML异常
包含库 #include <QtXml/QDomDocument> 再修改.pro文件 将 QT += core gui 后面添加 xml —> QT += core gui xml
- MVA Prototype Only User License
This App is only a protetype of MVA WP app, the intent is to demostrate to Leadership person about w ...
- python functools.partial
functools.partial 用一些默认参数包装一个可调用对象,返回结果是可调用对象,并且可以像原始对象一样对待 冻结部分函数位置函数或关键字参数,简化函数,更少更灵活的函数参数调用 refer ...
- nginx unit nodejs 模块试用
unit 对于nodejs 的支持是在10.25 发布的,基本能用,但是依然有好多问题,当前在测试的时候就发现,请求之后会block , 相关的issue 已经有人反馈了,最好使用源码编译,方便测 ...
- streamsets 3.5 的一些新功能
streamsets 3.5 有了一些新的特性以及增强,总之是越来越方便了,详细的可以 查看官方说明,以下简单例举一些比较有意义的. origins 新的pulsar 消费origin jdbc 多表 ...
- php 中的引用
php 有类似 C 中的指针 &. 但在 php 中叫 引用. 虽然和 传地址很像,但是差别很大.(估计底层实现应该差不多,只是猜想,有机会再研究) 这里有一个关于 php 的对象的赋值其实就 ...
- tomcat源码阅读之部署器
我们知道web应用是用Context实例表示的,而Context是部署到Host实例中的,因此tomcat的部署器是关联的Host实例.Context实例可以用WAR文件部署,也可以把整个web应用的 ...
- Upgrade to or Install Cinnamon 2.4 in Ubuntu
http://www.omgubuntu.co.uk/2014/11/install-cinnamon-2-4-ubuntu-14-04-lts sudo add-apt-repository ppa ...
- 【转】linux下解压.bz2压缩文件
原文网址:http://zhidao.baidu.com/question/90378903.html tar-c: 建立压缩档案-x:解压-t:查看内容-r:向压缩归档文件末尾追加文件-u:更新原压 ...
- 【转】每天一个linux命令(60):scp命令
原文网址:http://www.cnblogs.com/peida/archive/2013/03/15/2960802.html scp是secure copy的简写,用于在Linux下进行远程拷贝 ...