Universal Cup Judging System

Universal Cup

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

對於多邊形 $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.