「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 ...
随机推荐
- Unity3D 发布APK安卓环境配置步骤、安装、教程(含Java/Android)(超全流程)
Unity3D安卓环境配置运行 本文提供全流程,中文翻译.Chinar坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- 心分享. ...
- Fzu软工第二次作业-词频分析
(0)前言: Github项目 作业地址 (1)PSP表格: PSP2.1 Personal Software Process Stages 预估耗时(分钟) 实际耗时(分钟) Planning 计划 ...
- 练习SQL代码
---------PS:但凡有聚合函数(where),必然后Group by,Group by后面跟having ---------面试题 SELECT name,sum(fen) as s from ...
- android 发送UDP广播,搜寻server建立socket链接
应用场景:client(手机.pc)须要搜寻所在局域网内的server并获得server地址. 方法简单介绍:client发送UDP广播,服务收到广播后得到clientip地址,然后向client发送 ...
- GridControl 之 BandedGridView
https://documentation.devexpress.com/#WindowsForms/clsDevExpressXtraGridViewsBandedGridBandedGridVie ...
- 系列文章--从零开始学习ASP.NET MVC 1.0
从零开始学习ASP.NET MVC 1.0 (一) 开天辟地入门篇 从零开始学习 ASP.NET MVC 1.0 (二) 识别URL的Routing组件 从零开始学习 ASP.NET MVC 1.0 ...
- Python–logging模块知多少
我们在写程序的时候经常会打一些日志来帮助我们查找问题,这次学习一下logging模块,在python里面如何操作日志. 介绍一下logging模块,logging模块就是python里面用来操作日志的 ...
- hadoop之 node manager起不来, 执行mapreduce 程序hang住
现象: node manager起不来, 执行mapreduce 程序hang住 namenode 进程状态查询[root@hadp-master sbin]# jps8608 ResourceMan ...
- 【Bitmap Index】B-Tree索引与Bitmap位图索引的锁代价比较研究
通过以下实验,来验证Bitmap位图索引较之普通的B-Tree索引锁的“高昂代价”.位图索引会带来“位图段级锁”,实际使用过程一定要充分了解不同索引带来的锁代价情况. 1.为比较区别,创建两种索引类型 ...
- maven 指定 jdk 版本
方法1:直接修改 本地 settings.xml 文件 <profiles> </profiles> 之间加入 下面的 <profile> <id> ...