luogu P2093 [国家集训队]JZPFAR
要维护平面上点的信息,所以可以用KD-tree来维护,然后维护一个大小为\(k\)的堆,每次从根开始遍历,遇到一个点就看能不能作为前\(k\)远的点,也就是看能不能把堆中最近的点给替换掉.如果那个点在KD-tree上的控制区域中离要求的点的最远的点的距离比当前第\(k\)远距离小就不用访问了
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<vector>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#include<set>
#define LL long long
#define db double
using namespace std;
const int N=1e5+10;
int rd()
{
int x=0,w=1;char ch=0;
while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
return x*w;
}
int nd;
struct point
{
int d[2],i;
bool operator < (const point &bb) const {return d[nd]!=bb.d[nd]?d[nd]<bb.d[nd]:i<bb.i;}
}a[N],b[N],qwq;
struct node
{
LL d;
int i;
bool operator < (const node &bb) const {return d!=bb.d?d>bb.d:i<bb.i;}
};
priority_queue<node> hp;
int n,m,rt,ch[N][2],mx[N][2],my[N][2],szz;
void bui(int &o,int l,int r,int nnd)
{
if(l>r) return;
if(l==r)
{
o=b[l].i;
mx[o][0]=mx[o][1]=a[o].d[0];
my[o][0]=my[o][1]=a[o].d[1];
return;
}
int mid=(l+r)>>1;
nd=nnd;
nth_element(b+l,b+mid,b+r+1);
o=b[mid].i;
mx[o][0]=mx[o][1]=a[o].d[0];
my[o][0]=my[o][1]=a[o].d[1];
bui(ch[o][0],l,mid-1,nnd^1);
bui(ch[o][1],mid+1,r,nnd^1);
mx[o][0]=min(mx[o][0],min(mx[ch[o][0]][0],mx[ch[o][1]][0]));
mx[o][1]=max(mx[o][1],max(mx[ch[o][0]][1],mx[ch[o][1]][1]));
my[o][0]=min(my[o][0],min(my[ch[o][0]][0],my[ch[o][1]][0]));
my[o][1]=max(my[o][1],max(my[ch[o][0]][1],my[ch[o][1]][1]));
}
LL dis(point aa,point bb){return 1ll*(aa.d[0]-bb.d[0])*(aa.d[0]-bb.d[0])+1ll*(aa.d[1]-bb.d[1])*(aa.d[1]-bb.d[1]);}
LL expt(int o)
{
if(!o) return -1;
LL xx=max(mx[o][1]-qwq.d[0],qwq.d[0]-mx[o][0]),yy=max(my[o][1]-qwq.d[1],qwq.d[1]-my[o][0]);
return xx*xx+yy*yy;
}
void wk(int o)
{
if(!o||expt(o)<hp.top().d) return;
node nw=(node){dis(a[o],qwq),o};
if(nw<hp.top()) hp.pop(),hp.push(nw);
if(expt(ch[o][0])>expt(ch[o][1])) wk(ch[o][0]),wk(ch[o][1]);
else wk(ch[o][1]),wk(ch[o][0]);
}
int main()
{
n=rd();
for(int i=1;i<=n;++i) a[i].d[0]=rd(),a[i].d[1]=rd(),a[i].i=i,b[i]=a[i];
mx[0][0]=my[0][0]=1<<30,mx[0][1]=my[0][1]=-(1<<30);
bui(rt,1,n,0);
m=rd();
while(m--)
{
qwq.d[0]=rd(),qwq.d[1]=rd();
int k=rd();
while(!hp.empty()) hp.pop();
while(k--) hp.push((node){-1,0});
//szz=0;
wk(rt);
node an=hp.top();
printf("%d\n",an.i);
}
return 0;
}
luogu P2093 [国家集训队]JZPFAR的更多相关文章
- p2093 [国家集训队]JZPFAR
传送门 分析 首先给大家推荐一个非常好的KDTree笔记 here 此题就是y9ong优先队列维护距离最远的k个,最后输出队首元素即可 估价函数就是max和min两点到 询问点的最远距离 代码 #in ...
- P2093 [国家集训队]JZPFAR(KDTree)
传送门 类似于p4357 不过因为距离相等的时候要优先选择序号小的,所以要重载一下运算符 //minamoto #include<bits/stdc++.h> #define R regi ...
- luogu P2757 [国家集训队]等差子序列
题目链接 luogu P2757 [国家集训队]等差子序列 题解 线段树好题 我选择暴力 代码 // luogu-judger-enable-o2 #include<cstdio> inl ...
- luogu P2619 [国家集训队2]Tree I
题目链接 luogu P2619 [国家集训队2]Tree I 题解 普通思路就不说了二分增量,生成树check 说一下坑点 二分时,若黑白边权有相同,因为权值相同优先选白边,若在最有增量时出现黑白等 ...
- [Luogu P1829] [国家集训队]Crash的数字表格 / JZPTAB (莫比乌斯反演)
题面 传送门:洛咕 Solution 调到自闭,我好菜啊 为了方便讨论,以下式子\(m>=n\) 为了方便书写,以下式子中的除号均为向下取整 我们来颓柿子吧qwq 显然,题目让我们求: \(\l ...
- Luogu P1297 [国家集训队]单选错位
P1297 [国家集训队]单选错位 题目背景 原 <网线切割>请前往P1577 题目描述 gx和lc去参加noip初赛,其中有一种题型叫单项选择题,顾名思义,只有一个选项是正确答案.试卷上 ...
- Luogu P2619 [国家集训队2]Tree I(WQS二分+最小生成树)
P2619 [国家集训队2]Tree I 题意 题目描述 给你一个无向带权连通图,每条边是黑色或白色.让你求一棵最小权的恰好有\(need\)条白色边的生成树. 题目保证有解. 输入输出格式 输入格式 ...
- 【luogu P1494 [国家集训队]小Z的袜子】 题解
题目链接:https://www.luogu.org/problemnew/show/P1494 #include <cstdio> #include <algorithm> ...
- 【luogu P1903 [国家集训队]数颜色】 题解
题目链接:https://www.luogu.org/problemnew/show/P1903 裸的...带修莫队... 比较麻烦吧(对我来说是的) 两个变量分开记录查询和修改操作. #includ ...
随机推荐
- 说说 Activity、Intent、Service 是什么关系
他们都是 Android 开发中使用频率最高的类.其中 Activity 和 Service 都是 Android 四大组件之一.他俩都是Context 类的子类 ContextWrapper 的子类 ...
- vim命令行模式常见快捷方式
普通模式下的快捷键 快捷键 说明 i insert, 在光标所在处输入 I 在当前光标所在行的行首输入 a append, 在光标所在处后面输入 A 在当前光标所在行的行尾输入 o 在当前光标所在行的 ...
- http协议详解1
一.http协议url组成部分详解:1.协议类型2.ip(服务器地址)3.port(或域名)4.path(请求资源所在地址)5.?(资源地址与参数的分割符合)6.参数(请求参数)7.&(多个参 ...
- 阶段3 2.Spring_08.面向切面编程 AOP_9 spring基于注解的AOP配置
复制依赖和改jar包方式 src下的都复制过来. 复制到新项目里了 bean.xml里面复制上面一行代码到下面.把aop改成context. 配置spring容器创建时要扫描的包 Service的配置 ...
- fiddler抓取app的https的包
线上问题的排查有时候需要抓包,但是是https协议的,则需要安装证书 在Android 6.0 (API level 23)及以前,APP默认信任系统自带的CA证书以及用于导入的CA证书,Androi ...
- Jmeter+Ant+Jenkins接口自动化持续集成环境搭建(Linux)
一.安装说明 系统环境:CentOS release 6.4 JDK版本:jdk1.8.0_181 Jmeter版本:apache-jmeter-3.0 Ant版本:apache-ant-1.9.13 ...
- nginx子配置文件实例
[root@bogon conf.d]# cat /etc/nginx/conf.d/test6.conf server { listen 8085; server_name 192.168.0.20 ...
- pcap中不同包功能
1.不同包协议的功能 EAPoL:基于局域网的扩展认证协议 ICMPv6:(一般是四个连在一起)互联网控制协议第六套 DHCP Discover:请求分配IP DHCP Offer:你的IP是***, ...
- Golang基础(6):go的net/http用法
http包提供了HTTP客户端和服务端的实现 一:http客户端的几种方法 1. func (c *Client) Get(url string) (resp *Response, err error ...
- 2018-12-10 发布 vue全家桶实现的商城web-app,真实数据接口开发
项目地址:https://github.com/Rosen97/web-shop.git 博客地址:https://segmentfault.com/a/1190000017323841