QOJ.ac

QOJ

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

#7803. H形图形

统计

继去年“K-Shaped Figures”问题取得巨大成功后,今年我们又构思了一个创新的“H-Shaped Figures”问题。我们甚至已经为未来 24 年做好了规划。

我们称平面上的三条线段 $PQ$、$a$ 和 $b$ 构成一个 H 型图形,如果满足以下条件: 点 $P$ 严格位于线段 $a$ 内部,且线段 $PQ$ 与 $a$ 不共线; 点 $Q$ 严格位于线段 $b$ 内部,且线段 $PQ$ 与 $b$ 不共线; * 线段 $a$ 和 $b$ 没有公共点。

合法的 H 型图形与非法的 H 型图形

给定点 $P$ 和 $Q$ 的坐标,以及 $n$ 条候选线段作为 $a$ 和 $b$ 的备选。注意,给定的某些线段可能重合,但它们仍应被视为不同的线段。

请计算从给定的 $n$ 条线段中选择一条作为 $a$,另一条作为 $b$,使得它们与给定的线段 $PQ$ 构成 H 型图形的方法总数。

输入格式

每个测试包含多个测试用例。第一行包含测试用例的数量 $t$ ($1 \le t \le 10^5$)。

每个测试用例的第一行包含四个整数 $x_P, y_P, x_Q, y_Q$,表示点 $P$ 和 $Q$ 的坐标 ($-10^9 \le x_P, y_P, x_Q, y_Q \le 10^9$)。点 $P$ 和 $Q$ 不重合。

第二行包含一个整数 $n$,表示候选线段的数量 ($2 \le n \le 2 \cdot 10^5$)。

接下来的 $n$ 行中,第 $i$ 行包含四个整数 $x_{i,1}, y_{i,1}, x_{i,2}, y_{i,2}$,表示第 $i$ 条线段的端点坐标 ($-10^9 \le x_{i,1}, y_{i,1}, x_{i,2}, y_{i,2} \le 10^9$)。所有线段的长度均为正。

保证所有测试用例的 $n$ 之和不超过 $2 \cdot 10^5$。

输出格式

对于每个测试用例,输出使用给定的线段 $PQ$ 和两条候选线段构成 H 型图形的方法数。

样例

输入 1

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

输出 1

6

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.