time limit per test5 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard output

Berland amusement park shooting gallery is rightly acknowledged as one of the best in the world. Every day the country’s best shooters master their skills there and the many visitors compete in clay pigeon shooting to win decent prizes. And the head of the park has recently decided to make an online version of the shooting gallery. During the elaboration process it turned out that the program that imitates the process of shooting effectively, is needed. To formulate the requirements to the program, the shooting gallery was formally described. A 3D Cartesian system of coordinates was introduced, where the X axis ran across the gallery floor along the line, along which the shooters are located, the Y axis ran vertically along the gallery wall and the positive direction of the Z axis matched the shooting direction. Let’s call the XOY plane a shooting plane and let’s assume that all the bullets are out of the muzzles at the points of this area and fly parallel to the Z axis. Every clay pigeon can be represented as a rectangle whose sides are parallel to X and Y axes, and it has a positive z-coordinate. The distance between a clay pigeon and the shooting plane is always different for every target. The bullet hits the target if it goes through the inner area or border of the rectangle corresponding to it. When the bullet hits the target, the target falls down vertically into the crawl-space of the shooting gallery and cannot be shot at any more. The targets are tough enough, that’s why a bullet can not pierce a target all the way through and if a bullet hits a target it can’t fly on. In input the simulator program is given the arrangement of all the targets and also of all the shots in the order of their appearance. The program should determine which target was hit by which shot. If you haven’t guessed it yet, you are the one who is to write such a program.

Input

The first line contains an integer n (1 ≤ n ≤ 105) — the number of targets. Each of the subsequent n lines contains the description of a target. The target is described by five integers xl, xr, yl, yr, z, that determine it’s location in space (0 ≤ xl < xr ≤ 107, 0 ≤ yl < yr ≤ 107, 0 < z ≤ 107). The next line contains an integer m (1 ≤ m ≤ 105), determining the number of shots. Then in m lines shots are described. Every shot is determined by the coordinates of a bullet on the shooting plane (x, y) (0 ≤ x, y ≤ 107, the coordinates of bullets are integers). The shots are given in the order of their firing. The intervals between shots are large enough, and a target falls very quickly, that’s why assume that a falling target can not be an obstruction for all the shots following the one that hit it.

Output

For every shot in the single line print the number of the target which the shot has hit, or 0, if the bullet did not hit any target. The targets are numbered starting from 1 in the order in which they were given in the input data.

Examples

input

2

1 4 1 4 1

2 5 2 6 2

4

0 0

3 3

4 5

3 5

output

0

1

2

0

【题解】



给你n个靶子;

m个子弹;

问每个子弹能打到哪些靶子;

当然子弹打到靶子之后;那个靶子就会消失;

kd-tree把子弹作为元素加进去;

然后把每个靶子按照距离z升序排(顺序处理);

给每个靶子找子弹(这个靶子所在的范围里面子弹的顺序最小的那个);

然后把那个子弹从kd-tree中删掉;

继续找就好;

涉及到了kd-tree节点的删除;

#include <cstdio>
#include <algorithm> using namespace std; const int MAXN = 105000;
const int INF = 2100000000; struct target
{
int mi_n[2], ma_x[2], z, n;
}; struct point
{
int min, n, dot, d[2],fa,l,r,ma_x[2],mi_n[2];
}; int n, m, root, now,ans[MAXN] = { 0 }; target rec[MAXN];
point t[MAXN]; void input_data()
{
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
scanf("%d%d%d%d%d", &rec[i].mi_n[0], &rec[i].ma_x[0], &rec[i].mi_n[1], &rec[i].ma_x[1], &rec[i].z);
rec[i].n = i;
}
scanf("%d", &m);
for (int i = 1; i <= m; i++)
{
scanf("%d%d", &t[i].d[0], &t[i].d[1]);
t[i].n = i;
}
} bool cmp_1(point a, point b)
{
return a.d[now] < b.d[now];
} void gengxin(int father, int son)
{
if (t[father].min > t[son].min)
{
t[father].min = t[son].min;
t[father].dot = t[son].dot;
}
for (int i = 0;i <= 1;i++)
{
t[father].mi_n[i] = min(t[father].mi_n[i],t[son].mi_n[i]);
t[father].ma_x[i] = max(t[father].ma_x[i],t[son].ma_x[i]);
}
} void up_data(int rt)
{
t[rt].min = t[rt].n; t[rt].dot = rt; //dot可以说是当前这个子树的编号最小的点的节点。
if (t[rt].n == 0) //如果点已经删掉了
{
t[rt].min = INF;
t[rt].dot = 0;
t[rt].mi_n[0] = INF;
t[rt].mi_n[1] = INF;
t[rt].ma_x[0] = 0;
t[rt].ma_x[1] = 0;
}
int l = t[rt].l, r = t[rt].r;
if (l)
gengxin(rt, l);
if (r)
gengxin(rt, r);
} int build(int begin, int end, int fa,int fx)
{
int m = (begin + end) >> 1;
now = fx;
nth_element(t + begin, t + m, t + end + 1, cmp_1);
t[m].fa = fa;
for (int i = 0;i<=1;i++)
t[m].mi_n[i] = t[m].ma_x[i] = t[m].d[i];
if (begin < m)
t[m].l = build(begin, m - 1, m, 1 - fx);
if (m < end)
t[m].r = build(m + 1, end, m, 1 - fx);
up_data(m);
return m;
} bool inrange(int a,int b,int c)
{
return (a<=b && b <=c);
} int query(int rt,int r)
{
if (!rt)
return 0;
if (!t[rt].dot)
return 0;
if (rec[r].mi_n[0] <= t[rt].mi_n[0] && t[rt].ma_x[0] <= rec[r].ma_x[0]
&& rec[r].mi_n[1] <= t[rt].mi_n[1] && t[rt].ma_x[1] <= rec[r].ma_x[1])//这个子树里面的子弹全部在靶子的范围内;
return t[rt].dot;
if (rec[r].mi_n[0]>t[rt].ma_x[0] || rec[r].ma_x[0] < t[rt].mi_n[0] ||//全不在就结束
rec[r].mi_n[1]>t[rt].ma_x[1] || rec[r].ma_x[1] < t[rt].mi_n[1])
return 0;
int temp = 0;
if ( t[rt].n!=0 && rec[r].mi_n[0] <= t[rt].d[0] && t[rt].d[0] <= rec[r].ma_x[0]//当前这个节点;
&& rec[r].mi_n[1] <= t[rt].d[1] && t[rt].d[1] <= rec[r].ma_x[1])
temp = rt;
int zuo = t[rt].l,you = t[rt].r;
int temp1 = query(zuo,r);//递归处理左右节点
int temp2 = query(you,r);
if (temp1 !=0)
if (!temp)
temp = temp1;
else
{
if (t[temp1].n<t[temp].n)//注意不是把temp赋值成t[temp1].n;
temp = temp1;
}
if (temp2 !=0)
if (!temp)
temp = temp2;
else
if (t[temp2].n < t[temp].n)
temp = temp2;
return temp;
} void adjust(int rt) //删掉一个点后调整相关点的信息
{
up_data(rt);
if (rt != root)
adjust(t[rt].fa);
} bool cmp_2(target a, target b)
{
return a.z < b.z;
} void get_ans()
{
root = build(1, m, 0, 0);
sort(rec + 1, rec + 1 + n, cmp_2);
for (int i = 1; i <= n; i++)
{
now = i;
int hit = query(root, i);
if (hit != 0)
{
ans[t[hit].n] = rec[i].n;
t[hit].n = 0;
adjust(hit);
}
}
} void output_ans()
{
for (int i = 1; i <= m; i++)
printf("%d\n", ans[i]);
} int main()
{
input_data();
get_ans();
output_ans();
return 0;
}

【20.00%】【codeforces 44G】Shooting Gallery的更多相关文章

  1. 【 BowWow and the Timetable CodeForces - 1204A 】【思维】

    题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...

  2. 【50.00%】【codeforces 747C】Servers

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【20.23%】【codeforces 740A】Alyona and copybooks

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. 【50.00%】【codeforces 602C】The Two Routes

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【25.00%】【codeforces 584E】Anton and Ira

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【74.00%】【codeforces 747A】Display Size

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. 【20.51%】【codeforces 610D】Vika and Segments

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【codeforces 750A】New Year and Hurry

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  9. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

随机推荐

  1. Spring Boot 动态数据源(Spring 注解数据源)

    本文实现案例场景:某系统除了需要从自己的主要数据库上读取和管理数据外,还有一部分业务涉及到其他多个数据库,要求可以在任何方法上可以灵活指定具体要操作的数据库. 为了在开发中以最简单的方法使用,本文基于 ...

  2. 互信息 & 卡方 - 文本挖掘

    在做文本挖掘,特别是有监督的学习时,常常需要从文本中提取特征,提取出对学习有价值的分类,而不是把所有的词都用上,因此一些词对分类的作用不大,比如“的.是.在.了”等停用词.这里介绍两种常用的特征选择方 ...

  3. async和await在项目中的应用

    Async基础知识: async函数是ES7标准引入的语法,基于Generator函数实现的,也就是说是Generator函数的语法糖.什么是Generator函数?(留个坑) 返回值是Promise ...

  4. 8.2 Android灯光系统_led_class驱动

    android-5.0.2\hardware\libhardware\include\hardware\lights.h  //系统一些宏定义 android源码只带的灯光驱动在linux内核的dri ...

  5. 【SPOJ 694】Distinct Substrings

    [链接]h在这里写链接 [题意]     给你一个长度最多为1000的字符串     让你求出一个数x,这个x=这个字符串的不同子串个数; [题解]     后缀数组题.     把原串复制一份,加在 ...

  6. spark1.3.1使用基础教程 分类: B8_SPARK 2015-04-28 11:10 1651人阅读 评论(0) 收藏

      spark可以通过交互式命令行及编程两种方式来进行调用: 前者支持scala与python 后者支持scala.python与java 本文参考https://spark.apache.org/d ...

  7. Python中字符串的解压缩

    今天在用Streaming-Python处理一个MapReduce程序时,发现reducer失败,原由于耗费内存达到极限了.细致查看代码时,发现有一个集合里保存着URL,而URL长度是比較长的,直接保 ...

  8. Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)

    Crazy Bobo Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Tota ...

  9. SPOJ4491. Primes in GCD Table(gcd(a,b)=d素数,(1&lt;=a&lt;=n,1&lt;=b&lt;=m))加强版

    SPOJ4491. Primes in GCD Table Problem code: PGCD Johnny has created a table which encodes the result ...

  10. Android的NDK开发(3)————JNI数据类型的详解

    在Java中有两类数据类型:primitive types,如,int, float, char:另一种为reference types,如,类,实例,数组. 注意:数组,不管是对象数组还是基本类型数 ...