Universal Cup Judging System

Universal Cup

時間限制: 2.0 s 記憶體限制: 1024 MB 總分: 100 可 Hack ✓
统计

對於多邊形 $P_1$ 同多邊形 $P_2$,如果喺 $P_2$ 內部或者邊界上面嘅每個點都同樣喺 $P_1$ 嘅內部或者邊界上面,就稱多邊形 $P_1$ 包含多邊形 $P_2$。對於多邊形 $P_1$ 同多邊形 $P_2$,如果喺 $P_2$ 內部或者邊界上面嘅每個點都嚴格位於 $P_1$ 嘅內部(冇任何點喺邊界上面),就稱多邊形 $P_1$ 嚴格包含 $P_2$。

Panda 有兩個凸多邊形 $P$ 同 $Q$。多邊形 $P$ 有 $n$ 個頂點,而多邊形 $Q$ 有 $m$ 個頂點。題目保證 $Q$ 被 $P$ 嚴格包含。

你需要幫 Panda 搵出,從多邊形 $P$ 入面恰好揀出 $3$ 個唔同嘅頂點組成三角形 $P_\Delta$,令到 $P_\Delta$(非嚴格)包含多邊形 $Q$ 嘅總方案數。

Figure 1

輸入格式

第一行包含一個整數 $T$($1 \le T \le 1000$),代表測試資料嘅組數。

對於每組測試資料,第一行包含一個整數 $n$($3 \le n \le 3 \cdot 10^5$),代表 $P$ 嘅頂點數量。

接落嚟嘅 $n$ 行,每行包含兩個整數 $x, y$($|x|, |y| \le 10^9$),代表 $P$ 嘅頂點座標。題目保證頂點按逆時針順序畀出,而且任意三個頂點都唔共線。

下一行包含一個整數 $m$($3 \le m \le 3 \cdot 10^5$),代表 $Q$ 嘅頂點數量。

接落嚟嘅 $m$ 行,每行包含兩個整數 $x, y$($|x|, |y| \le 10^9$),代表 $Q$ 嘅頂點座標。題目保證頂點按逆時針順序畀出,任意三個頂點都唔共線,而且 $Q$ 被 $P$ 嚴格包含。

題目保證所有測試資料入面嘅 $\sum n$ 同 $\sum m$ 都唔超過 $5 \cdot 10^5$。

輸出格式

對於每組測試資料,喺單獨一行入面輸出一個整數,代表答案。

範例

輸入 1

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

輸出 1

2
4
6

說明

對於第一個範例,如圖所示,多邊形 $P$ 係 $ABCDEF$,而多邊形 $Q$ 係 $GHIJ$。包含 $Q$ 嘅三角形係 $\triangle ACE$ 同 $\triangle BDF$。

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.