Universal Cup Judging System

Universal Cup

Süre Sınırı: 4.0 s Bellek Sınırı: 1024 MB Toplam puan: 100 Hack'lenebilir ✓
İstatistikler

A hockey rink for hogs has the shape of a convex polygon $A$ with vertices $A_1, \ldots, A_n$. At vertex $A_i$ there is a net numbered $i$.

The rink lies entirely strictly inside another convex polygon $B$ with vertices $B_1, \ldots, B_m$. Polygon $B$ bounds a dangerous zone: a spectator is not allowed to be inside $B$, but may stand on its boundary or outside $B$.

The nets open toward the inside of the rink. From the outside, each net is protected by a small opaque fence consisting of two panels placed along the two sides of the rink incident to vertex $A_i$.

A spectator at point $P$ can see a goal scored into net $i$ if the ray starting at $A_i$ and passing through $P$ lies inside the interior angle of polygon $A$ at vertex $A_i$, or on its boundary. Otherwise, the protective fence of this net blocks the view. The fence of net $i$ can block the view only of net $i$ and does not affect the visibility of the other nets.

Because of the strength and mass of the hogs, a net into which a goal is scored breaks immediately and is no longer used. The match ends when all nets are broken. The order in which the goals are scored is given by a permutation $p_1, p_2, \ldots, p_n$: the $k$-th goal is scored into net $p_k$.

Before the $k$-th goal, the spectator wants to change his location: choose one valid point $P$ outside the interior of $B$, move to it, and remain there until the end of the match. Independently for each $k$ from $1$ to $n$, determine the maximum number of goals among the remaining ones (into nets $p_k, \ldots, p_n$) that the spectator will still be able to see after choosing the best possible point $P$.

Input

The first line contains one integer $1 \le T \le 10^5$ — the number of test cases. The descriptions of the $T$ test cases follow.

The first line of each test case contains two integers $n$ and $m$ ($3 \le n, m \le 5 \cdot 10^5$) — the numbers of vertices of polygons $A$ and $B$, respectively.

The next $n$ lines each contain two integers $x_i$ and $y_i$ — the coordinates of vertex $A_i$. The vertices of polygon $A$ are given in counterclockwise order.

The next $m$ lines each contain two integers $z_i$ and $v_i$ — the coordinates of vertex $B_i$. The vertices of polygon $B$ are given in counterclockwise order.

All vertex coordinates of the polygons are integers whose absolute values do not exceed $10^9$. It is guaranteed that both polygons are strictly convex, and that polygon $A$ lies entirely strictly inside polygon $B$.

The last line of each test case contains a permutation $p_1, p_2, \ldots, p_n$ of the numbers from $1$ to $n$ — the order of the nets into which the goals are scored.

It is guaranteed that the sum of $n$ over all test cases does not exceed $5 \cdot 10^5$, and the sum of $m$ over all test cases does not exceed $5 \cdot 10^5$.

Output

For each test case, output $n$ integers: the $k$-th integer must be equal to the maximum number of future goals the spectator can see if they choose the best possible valid point $P$ before the $k$-th goal.

Examples

Input 1

2
3 4
1 1
3 1
1 3
0 0
4 0
4 4
0 4
3 2 1
4 3
-1 2
1 2
2 4
-2 4
0 -1
6 5
-6 5
1 2 3 4

Output 1

1 1 1
2 2 1 1

Note

Consider the second sample test case.

Before the first goal, the spectator can choose, for example, the point $(0, 10)$. From this point, the goals into nets $1$ and $2$ are visible, so the spectator can see $2$ future goals.

Before the second goal, net $1$ is already broken. The spectator can choose the point $(-3.5, 2.5)$, which lies on the boundary of polygon $B$. From this point, the goals into nets $2$ and $3$ are visible, so the spectator can again see $2$ future goals.

Before the third goal, only nets $3$ and $4$ remain. There is no valid point from which both of these goals are visible at the same time. However, the spectator can choose, for example, the point $(3, 2)$ on the boundary of $B$ and see the goal into net $4$. Therefore, the answer for this moment is $1$.

Before the fourth goal, only net $4$ remains. The spectator can stay at point $(3, 2)$ and see the last goal. Therefore, the answer is also $1$.

Thus, for the second sample test case, the answers are $2, 2, 1, 1$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.