#P2603. [ZJOI2008] 无序运动

    ID: 1616 远端评测题 3000ms 250MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2008各省省选浙江概率论,统计向量AC 自动机

[ZJOI2008] 无序运动

Description

Dr. D has conducted in-depth research in physics, with theorems in classical physics, astrophysics, and quantum physics named after him. Recently, he has been fascinated by the irregularity of particle motion. Firmly believing in the Bible, he is convinced that anything created by God must be orderly and rational, rather than random and chaotic.

After long study, Dr. D found many trajectory fragments that appear quite frequently and stored them in a large database. He needs you to write a program that, for a given particle trajectory, counts the number of occurrences of each trajectory fragment from the database.

For clarity, we define a particle’s trajectory as a sequence of points on a 2D plane, (P1,P2,,PN)(P_1, P_2, \dots, P_N). A subarray [i,j][i, j] of the point sequence PP is defined as a contiguous subsequence in PP, (Pi,Pi+1,,Pj)(P_i, P_{i + 1}, \dots, P_j). A subarray [u,v][u, v] of the point sequence PP is called an occurrence of the point sequence Q=(Q1,Q2,,Qvu+1)Q = (Q_1, Q_2, \dots, Q_{v - u + 1}) in PP if and only if, after a finite number of translations, rotations, reflections, and scalings, we obtain QQ' such that 1kvu+1\forall 1 \le k \le v - u + 1, Qk=Pu+k1Q'_k = P_{u + k - 1}.

Explanations for the four operations on point sequences: |Operation|Explanation| |:-:|:-:| |Translation|Let the translation vector be (dx,dy)(d_x, d_y). Then any point (x,y)(x, y) is mapped to (x+dx,y+dy)(x + d_x, y + d_y).| |Rotation|Let the rotation angle be tt. Then any point (x,y)(x, y) is mapped to (xcostysint,xsint+ycost)(x \cos t - y \sin t, x \sin t + y \cos t).| |Reflection|Any point (x,y)(x, y) is mapped to (x,y)(x, -y).| |Scaling|Let the scaling factor be p(p0)p (p \ne 0). Then any point (x,y)(x, y) is mapped to (px,py)(px, py).|

Input Format

The first line contains two integers N,MN, M, representing the size of the point sequence of the trajectory to be processed and the number of trajectory fragments in the database, respectively.

The next MM lines describe each trajectory fragment in order. Each line starts with a positive integer KK, the length of the point sequence of that fragment. Then 2K2K integers follow, describing the KK points’ xx- and yy-coordinates in order.

The next line contains 2N2N integers, describing the xx- and yy-coordinates of the NN points in the point sequence of the trajectory to be processed, in order.

Note: In every trajectory in the input, any two adjacent points are different.

Output Format

Output MM lines. For each fragment, output the number of its occurrences in the trajectory to be processed, in order.

3 2
2 17 0 10 1
3 0 0 1 0 1 -1
0 0 1 0 1 1

2
1

Hint

Let the total length of all fragments be LL.

Constraints:

  • For 30%30\% of the testdata, N,M,K100N, M, K \le 100, L500L \le 500.
  • For 50%50\% of the testdata, N,M,K1000N, M, K \le 1000, L5000L \le 5000.
  • For 100%100\% of the testdata, N,K2×105N, K \le 2 \times 10 ^ 5, L2×106L \le 2 \times 10 ^ 6, and it is guaranteed that the absolute value of every given point coordinate in the input does not exceed 10410 ^ 4.

Translated by ChatGPT 5