#P15955. [ICPC 2018 Jakarta R] Artilleries and Defensive Walls

[ICPC 2018 Jakarta R] Artilleries and Defensive Walls

题目描述

Sauville has been engulfed in a devastating war with its neighboring country, Norland, for centuries. Their border can be represented as a straight horizontal line y=0y = 0, where all areas for y<0y < 0 belong to Sauville and all areas for y>0y > 0 belong to Norland.

Norland has deployed NN of its artilleries at position (xi,yi)(x_i, y_i) where yi>0y_i > 0. In addition, Norland also has built MM defensive walls. Each defensive wall can be represented as a tuple xj1,xj2,yj\langle x_{j1}, x_{j2}, y_j \rangle, which is a horizontal line segment spanned from (xj1,yj)(x_{j1}, y_j) to (xj2,yj)(x_{j2}, y_j), where xj1<xj2x_{j1} < x_{j2} and yj>0y_j > 0. It is known to Sauville that no Norland’s artillery is located at any of its defensive walls (including its endpoints), and no two artilleries are at the same position. It is also known that no two walls (including their endpoints) are sharing a common point.

Sauville has decided to build a watchtower to observe any suspicious activity on any Norland’s artilleries. As the cost to build one watchtower is almost astronomical for Sauville, they can only afford to build one. Thus, QQ position candidates (xk,yk)(x_k, y_k) where yk<0y_k < 0 for the watchtower have been proposed. If the watchtower is built at (x,y)(x, y), then all artilleries which lie on the line-of-sight from (x,y)(x, y) can be observed (visible) by the watchtower. A position (xi,yi)(x_i, y_i) lies on the line-of-sight from (x,y)(x, y) if and only if the straight line connecting (xi,yi)(x_i, y_i) and (x,y)(x, y) does not intersect with any defensive walls (including its endpoints); in other words, there should be no point (x,y)(x', y') such that (x,y)(x', y') lies on a defensive wall and also on the line segment between (xi,yi)(x_i, y_i) and (x,y)(x, y). Note that an artillery does not affect the visibility of any other artilleries from the watchtower.

Your task in this problem is to determine the number of Norland’s artilleries which can be observed from each proposed watchtower position.

输入格式

Input begins with a line containing three integers: NN MM QQ (1N400001 \leq N \leq 40000; 0M50 \leq M \leq 5; 1Q400001 \leq Q \leq 40000) representing the number of artilleries, the number of defensive walls, and the number of proposed watchtower positions, respectively. The next NN lines, each contains two integers: xix_i yiy_i (106xi106-10^6 \leq x_i \leq 10^6; 0<yi1060 < y_i \leq 10^6) representing the position of the ithi^{th} artillery for i=1Ni = 1 \ldots N. The next MM lines, each contains three integers: xj1x_{j1} xj2x_{j2} yjy_j (106xj1<xj2106-10^6 \leq x_{j1} < x_{j2} \leq 10^6; 0<yj1060 < y_j \leq 10^6) representing the position of the jthj^{th} defensive wall for j=1Mj = 1 \ldots M. The next QQ lines, each contains two integers: xkx_k yky_k (106xk106-10^6 \leq x_k \leq 10^6; 106yk<0-10^6 \leq y_k < 0) representing a proposed position for the watchtower.

输出格式

For each proposed watchtower position in the same order as input, output in a line a single integer representing the number of Norland’s artilleries which can be observed from the proposed position.

6 2 3
0 2
0 15
5 7
15 15
35 12
45 10
5 20 5
25 40 10
0 -5
5 -10
20 -15
4
3
2

提示

Explanation for the sample input/output

The position of all artilleries, defensive walls, and proposed watchtowers are shown in the following figure.

:::align{center} :::

  • The first proposed watchtower (0,5)(0, -5) can observe 44 artilleries, i.e. at (0,2)(0, 2), (0,15)(0, 15), (5,7)(5, 7), and (45,10)(45, 10).
  • The second proposed watchtower (5,10)(5, -10) can observe 33 artilleries, i.e. at (0,2)(0, 2), (0,15)(0, 15), and (45,10)(45, 10).
  • The third proposed watchtower (20,15)(20, -15) can observe 22 artilleries, i.e. at (0,2)(0, 2) and (45,10)(45, 10).