#P13588. [NWRRC 2023] H-Shaped Figures

    ID: 15451 远端评测题 2000ms 1024MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>计算几何树状数组2023ICPC极角排序NWRRC

[NWRRC 2023] H-Shaped Figures

题目描述

After a huge success of the last year's "K-Shaped Figures" problem, we've come up with an innovative "H-Shaped Figures" problem for this year. And we have some plans for the next 24 years.

Let's say that three segments PQPQ, aa, and bb on a plane form an H-shaped figure if:

  • point PP lies strictly inside segment aa, and segments PQPQ and aa are not collinear;
  • point QQ lies strictly inside segment bb, and segments PQPQ and bb are not collinear;
  • segments aa and bb do not have common points.

You are given the coordinates of points PP and QQ, along with nn candidate segments for aa and bb. Note that some of the given segments may coincide, but they should still be treated as different segments.

Find the number of possible ways to choose one of the given nn segments as aa and another one as bb to form an H-shaped figure along with the given segment PQPQ.

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1051 \le t \le 10^5). The description of the test cases follows.

The first line of each test case contains four integers xP,yP,xQ,yQx_P, y_P, x_Q, y_Q, denoting the coordinates of points PP and QQ (109xP,yP,xQ,yQ109-10^9 \le x_P, y_P, x_Q, y_Q \le 10^9). Points PP and QQ do not coincide.

The second line contains a single integer nn, denoting the number of candidate segments (2n21052 \le n \le 2 \cdot 10^5).

The ii-th of the following nn lines contains four integers xi,1,yi,1,xi,2,yi,2x_{i,1}, y_{i,1}, x_{i,2}, y_{i,2}, denoting the coordinates of the endpoints of the ii-th segment ($-10^9 \le x_{i,1}, y_{i,1}, x_{i,2}, y_{i,2} \le 10^9$). All segments have positive lengths.

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5.

输出格式

For each test case, print the number of ways to form an H-shaped figure using the given segment PQPQ and two of the candidate segments.

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
6