#abc211f. F - Rectilinear Polygons

F - Rectilinear Polygons

Score : 600600 points

问题描述

我们有 NN 个在 xyxy 平面上的多边形。
这些多边形的所有边都与 xx 轴或 yy 轴平行,并且每个内角为 9090270270 度。所有这些多边形都是简单的。
ii 个多边形有 MiM_i 个顶点,其中第 jj 个顶点坐标为 (xi,j,yi,j)(x_{i, j}, y_{i, j})
该多边形的边是由第 jj 个顶点和第 (j+1)(j+1) 个顶点连接而成的线段。(假设 (Mi+1)(M_i+1)-th 顶点是第 11 个顶点。)

一个多边形是简单的,当...

对于它的任何两条不相邻的边,它们之间都不会相交(交叉或接触)。

您将获得 QQ 个查询。对于每个 i=1,2,,Qi = 1, 2, \dots, Q,第 ii 个查询如下所示。

  • 在这 NN 个多边形中,有多少个多边形包含点 (Xi+0.5,Yi+0.5)(X_i + 0.5, Y_i + 0.5) 在其内部?

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

We have NN polygons on the xyxy-plane.
Every side of these polygons is parallel to the xx- or yy-axis, and every interior angle is 9090 or 270270 degrees. All of these polygons are simple.
The ii-th polygon has MiM_i corners, the jj-th of which is (xi,j,yi,j)(x_{i, j}, y_{i, j}).
The sides of this polygon are segments connecting the jj-th and (j+1)(j+1)-th corners. (Assume that (Mi+1)(M_i+1)-th corner is the 11-st corner.)

A polygon is simple when...

for any two of its sides that are not adjacent, they do not intersect (cross or touch) each other.

You are given QQ queries. For each i=1,2,,Qi = 1, 2, \dots, Q, the ii-th query is as follows.

  • Among the NN polygons, how many have the point (Xi+0.5,Yi+0.5)(X_i + 0.5, Y_i + 0.5) inside them?

Constraints

  • 1N1051 \leq N \leq 10^5
  • 4Mi1054 \leq M_i \leq 10^5
  • Each MiM_i is even.
  • iMi4×105\sum_i M_i \leq 4 \times 10^5
  • 0xi,j,yi,j1050 \leq x_{i, j}, y_{i, j} \leq 10^5
  • (xi,j,yi,j)(xi,k,yi,k)(x_{i, j}, y_{i, j}) \neq (x_{i, k}, y_{i, k}) if jkj \neq k.
  • xi,j=xi,j+1x_{i, j} = x_{i, j+1} for j=1,3,Mi1j = 1, 3, \dots M_i-1.
  • yi,j=yi,j+1y_{i, j} = y_{i, j+1} for j=2,4,Mij = 2, 4, \dots M_i. (Assume yi,Mi+1=yi,1y_{i, M_i +1} = y_{i, 1}.)
  • The given polygons are simple.
  • 1Q1051 \leq Q \leq 10^5
  • 0Xi,Yi<1050 \leq X_i, Y_i \lt 10^5
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

M1M_1

x1,1x_{1, 1} y1,1y_{1, 1} x1,2x_{1, 2} y1,2y_{1, 2} \dots x1,M1x_{1, M_1} y1,M1y_{1, M_1}

M2M_2

x2,1x_{2, 1} y2,1y_{2, 1} x2,2x_{2, 2} y2,2y_{2, 2} \dots x2,M2x_{2, M_2} y2,M2y_{2, M_2}

\vdots

MNM_N

xN,1x_{N, 1} yN,1y_{N, 1} xN,2x_{N, 2} yN,2y_{N, 2} \dots xN,MNx_{N, M_N} yN,MNy_{N, M_N}

QQ

X1X_1 Y1Y_1

X2X_2 Y2Y_2

\vdots

XQX_Q YQY_Q

Output

Print QQ lines.
The ii-th line should contain the answer to the ii-th query.

Sample Input 1

3
4
1 2 1 4 3 4 3 2
4
2 5 2 3 5 3 5 5
4
5 6 5 5 3 5 3 6
3
1 4
2 3
4 5

Sample Output 1

0
2
1


Note that different polygons may cross or touch each other.

Sample Input 2

2
4
12 3 12 5 0 5 0 3
12
1 1 1 9 10 9 10 0 4 0 4 6 6 6 6 2 8 2 8 7 2 7 2 1
4
2 6
4 4
6 3
1 8

Sample Output 2

0
2
1
1


Although the polygons are simple, they may not be convex.

update @ 2024/3/10 09:26:31