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$ の厳密な内部にある(周上に点が 1 つもない)とき、多角形 $P_1$ は $P_2$ を厳密に含むといいます。

Panda は 2 つの凸多角形 $P$ と $Q$ を持っています。多角形 $P$ は $n$ 個の頂点を持ち、多角形 $Q$ は $m$ 個の頂点を持ちます。$Q$ は $P$ に厳密に含まれることが保証されます。

多角形 $P$ からちょうど $3$ 個の相異なる頂点を選んで三角形 $P_\Delta$ を作るとき、$P_\Delta$ が(厳密でなくともよい意味で)多角形 $Q$ を含むような選び方の総数を Panda のために求めてください。

Figure 1

入力

1 行目には、テストケースの個数を表す 1 つの整数 $T$($1 \le T \le 1000$)が与えられます。

各テストケースについて、1 行目には $P$ の頂点数を表す整数 $n$($3 \le n \le 3 \cdot 10^5$)が与えられます。

続く $n$ 行には、それぞれ 2 つの整数 $x, y$($|x|, |y| \le 10^9$)が与えられ、$P$ の頂点の座標を表します。頂点は反時計回りの順に与えられ、どの 3 頂点も同一直線上にないことが保証されます。

次の行には、$Q$ の頂点数を表す整数 $m$($3 \le m \le 3 \cdot 10^5$)が与えられます。

続く $m$ 行には、それぞれ 2 つの整数 $x, y$($|x|, |y| \le 10^9$)が与えられ、$Q$ の頂点の座標を表します。頂点は反時計回りの順に与えられ、どの 3 頂点も同一直線上になく、かつ $Q$ は $P$ に厳密に含まれることが保証されます。

すべてのテストケースにおける $\sum n$ と $\sum m$ はともに $5 \cdot 10^5$ を超えないことが保証されます。

出力

各テストケースについて、答えを表す整数を 1 行に出力してください。

入出力例

入力 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

注記

1 番目の例では、図に示されている通り、多角形 $P$ は $ABCDEF$ であり、多角形 $Q$ は $GHIJ$ です。三角形 $\triangle ACE$ と $\triangle BDF$ が $Q$ を含む三角形です。

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.