传送门

分析

首先给大家推荐一个非常好的KDTree笔记 here

此题就是用优先队列维护距离最远的k个,最后输出队首元素即可

估价函数就是max和min两点到

询问点的最远距离

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define int long long
const int inf = 1e18;
struct kd {
int d[],mx[],mn[],le,ri,id;
};
kd t[],now;
int n,m,root,wh;
inline bool operator < (kd a,kd b){
return a.d[wh]<b.d[wh];
}
struct node {
int d,id;
};
inline bool operator < (node a,node b){
return a.d>b.d||((a.d==b.d)&&(a.id<b.id));
}
inline void up(int rt){
for(int i=;i<;i++){
t[rt].mn[i]=min(t[rt].mn[i],min(t[t[rt].le].mn[i],t[t[rt].ri].mn[i]));
t[rt].mx[i]=max(t[rt].mx[i],max(t[t[rt].le].mx[i],t[t[rt].ri].mx[i]));
}
}
inline void build(int &x,int le,int ri,int wwh){
wh=wwh;
int mid=(le+ri)>>;
x=mid;
nth_element(t+le,t+x,t+ri+);
for(int i=;i<;i++)
t[x].mx[i]=t[x].mn[i]=t[x].d[i];
if(le<x)build(t[x].le,le,mid-,wwh^);
if(ri>x)build(t[x].ri,mid+,ri,wwh^);
up(x);
}
priority_queue<node>q;
inline int getd(kd a,kd b){
return (a.d[]-b.d[])*(a.d[]-b.d[])+(a.d[]-b.d[])*(a.d[]-b.d[]);
}
inline int calc(int x){
if(!x)return -inf;
int res=;
for(int i=;i<;i++)
res+=max((t[x].mx[i]-now.d[i])*(t[x].mx[i]-now.d[i]),(t[x].mn[i]-now.d[i])*(t[x].mn[i]-now.d[i]));
return res;
}
inline void qurey(int x){
if(!x)return;
int dl=calc(t[x].le),dr=calc(t[x].ri),d=getd(t[x],now);
if(d>q.top().d||(d==q.top().d&&t[x].id<q.top().id)){
q.pop();
q.push((node){d,t[x].id});
}
if(dl>dr){
if(dl>=q.top().d)qurey(t[x].le);
if(dr>=q.top().d)qurey(t[x].ri);
}else {
if(dr>=q.top().d)qurey(t[x].ri);
if(dl>=q.top().d)qurey(t[x].le);
}
}
signed main(){
int i,j,k;
t[].mn[]=t[].mn[]=inf;
t[].mx[]=t[].mx[]=-inf;
scanf("%lld",&n);
for(i=;i<=n;i++){
scanf("%lld%lld",&t[i].d[],&t[i].d[]);
t[i].id=i;
}
build(root,,n,);
scanf("%lld",&m);
for(i=;i<=m;i++){
while(!q.empty())q.pop();
scanf("%lld%lld%lld",&now.d[],&now.d[],&k);
for(j=;j<=k;j++)q.push((node){-,-});
qurey(root);
printf("%lld\n",q.top().id);
}
return ;
}

p2093 [国家集训队]JZPFAR的更多相关文章

  1. P2093 [国家集训队]JZPFAR(KDTree)

    传送门 类似于p4357 不过因为距离相等的时候要优先选择序号小的,所以要重载一下运算符 //minamoto #include<bits/stdc++.h> #define R regi ...

  2. luogu P2093 [国家集训队]JZPFAR

    传送门 要维护平面上点的信息,所以可以用KD-tree来维护,然后维护一个大小为\(k\)的堆,每次从根开始遍历,遇到一个点就看能不能作为前\(k\)远的点,也就是看能不能把堆中最近的点给替换掉.如果 ...

  3. [国家集训队]JZPFAR

    嘟嘟嘟 k-d tree模板之二:查询第k大距离.(所以是怎么上黑的) 因为k-d tree的查询就是暴力嘛,所以我就想到了一个很暴力的做法:每一次查询用一个长度为k的优先队列维护.按距离递增,编号递 ...

  4. luogu2093 [国家集训队]JZPFAR

    题面不符?-- #include <algorithm> #include <iostream> #include <cstdio> using namespace ...

  5. [国家集训队2012]JZPFAR

    [国家集训队2012]JZPFAR 题目 平面上有n个点.现在有m次询问,每次给定一个点(px, py)和一个整数k,输出n个点中离(px, py)的距离第k大的点的标号.如果有两个(或多个)点距离( ...

  6. BZOJ 2039: [2009国家集训队]employ人员雇佣

    2039: [2009国家集训队]employ人员雇佣 Time Limit: 20 Sec  Memory Limit: 259 MBSubmit: 1369  Solved: 667[Submit ...

  7. BZOJ 2038: [2009国家集训队]小Z的袜子(hose) [莫队算法]【学习笔记】

    2038: [2009国家集训队]小Z的袜子(hose) Time Limit: 20 Sec  Memory Limit: 259 MBSubmit: 7687  Solved: 3516[Subm ...

  8. BZOJ 2038: [2009国家集训队]小Z的袜子(hose)

    2038: [2009国家集训队]小Z的袜子(hose) Time Limit: 20 Sec  Memory Limit: 259 MBSubmit: 7676  Solved: 3509[Subm ...

  9. [转] ACM中国国家集训队论文集目录(1999-2009)

    国家集训队1999论文集 陈宏:<数据结构的选择与算法效率——从IOI98试题PICTURE谈起>来煜坤:<把握本质,灵活运用——动态规划的深入探讨>齐鑫:<搜索方法中的 ...

随机推荐

  1. GOF23设计模式之原型模式(prototype)

    一.原型模式概述 1.通过new产生一个对象需要非常繁琐的数据准备和访问权限,则可以使用原型模式. 2.就是java中的克隆技术,以某个对象为原型,复制出新的对象,显然,新的对象具备原型对象的特点. ...

  2. 了解IHttpModule接口事件执行顺便 获取Session

    本文转载自:http://www.cnblogs.com/eflylab/archive/2008/05/29/1209767.html 最近公司一个项目让人SQL注入了-为了临时先解决这个问题,使攻 ...

  3. 微服务监控之三:Prometheus + Grafana Spring Boot 应用可视化监控

    一.Springboot增加Prometheus 1.Spring Boot 应用暴露监控指标,添加如下依赖 <dependency> <groupId>org.springf ...

  4. canvas之画矩形

    <canvas id="canvas" width="600" height="500" style="background ...

  5. json-lib使用笔记

    今天再来记录一款生成JSON的工具——json-lib,它比较与我之前使用的FastJSON来说,使用都是很简单的,但是要使用json-lib要需要的jar包可真不少,所需要的依赖jar有八九个之多, ...

  6. 初探asciinema

    在学习c++的时候想到so库注入到某些程序中,网上查了一些资料,发现了一些比较好玩的程序,分享一下. 主要可以对操作的进行视频回放,类似堡垒机的功能 安装: pip3 install asciinem ...

  7. Linux常用命令及使用方法

    一.Linux命令格式 command [-option] [parameter1] ..... 即:命令名 [选项] [参数] 选项:控制命令 参数:可有0个,1个或多个 二.常用命令及用法 1.与 ...

  8. 第三章:使用 Android Studio 编程[Learn Android Studio 汉化教程]

    Learn Android Studio 汉化教程 Android Studio 本章包含如何在Android Studio中书写或生成代码. Android Studio 使用面向对象编程的思想来生 ...

  9. Django学习---缓存

    缓存 由于Django是动态网站,所有每次请求均会去数据进行相应的操作,当程序访问量大时,耗时必然会更加明显,最简单解决方式是使用:缓存. 缓存将一个某个views的返回值保存至内存或者memcach ...

  10. jQuery基本API小结(上)--选择器-DOM操作-动画-Ajax

    一.JQuery基础选择器 1.基本选择器(CSS选择器) 2.$()中的()不一定是指定元素,也可能是函数. 3.“*”号选择器,它的功能是获取页面中的全部元素:$(“*”). 由于使用*选择器获取 ...