「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 ...
随机推荐
- [python] 基于词云的关键词提取:wordcloud的使用、源码分析、中文词云生成和代码重写
1. 词云简介 词云,又称文字云.标签云,是对文本数据中出现频率较高的“关键词”在视觉上的突出呈现,形成关键词的渲染形成类似云一样的彩色图片,从而一眼就可以领略文本数据的主要表达意思.常见于博客.微博 ...
- 阿里java面试题
引言 其实本来真的没打算写这篇文章,主要是LZ得记忆力不是很好,不像一些记忆力强的人,面试完以后,几乎能把自己和面试官的对话都给记下来.LZ自己当初面试完以后,除了记住一些聊过的知识点以外,具体的内容 ...
- docker使用web界面管理Registry
1:安装 docker-registry-web项目 [root@Docker ~]#docker pull atcol/docker-registry-ui 2:docker run镜像 ...
- net core web服务器实现
net core 系列 18 web服务器实现 一. ASP.NET Core Module 在介绍ASP.NET Core Web实现之前,先来了解下ASP.NET Core Module.该模块是 ...
- 【WebForm】知识笔记
一.ashx介绍以及ashx文件与aspx文件之间的区别 ashx是什么文件? .ashx 文件用于写web handler的. .ashx文件与.aspx文件类似,可以通过它来调用HttpHandl ...
- test20180830
所有试题限制均为128MB,1Sec 总分100(•́へ•́╬). 试题一 A题 问题描述: Bob 有 n 个士兵,他们排成一列按照从左到右编号为 1 到 n,每个士兵都有自己的 IQ 值,Bob ...
- 转-java编译时error: illegal character '\ufeff' 的解决办法-https://blog.csdn.net/t518vs20s/article/details/80833061
原文链接:https://blog.csdn.net/shixing_11/article/details/6976900 最近开发人员通过SVN提交了xxx.java文件,因发布时该包有问题需要回退 ...
- NSDate 时间加减
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/pearlhuzhu/article/details/26227393 NSDate有个类别,例如以下 ...
- AQS源码分析
AQS全程为AbstractQueuedSynchronizer,其定义了一套多线程访问共享资源的同步框架,大部分的同步类的实现都依赖于他,比如ReentrantLock,ReentrantReadW ...
- python之 列表常用方法
更多列表的使用方法和API,请参考Python文档:http://docs.python.org/2/library/functions.html append:用于在列表末尾追加新对象: # app ...