|
||||||||||
Rikka with LinesTime Limit: 10000/5000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)Total Submission(s): 51 Accepted Submission(s): 3 Problem Description Plane geometry is an important branch of elementary mathematics. When Rikka was a middle school student, she learns a lot of theories about lines, triangles, and circles. As the time goes on, Rikka has learned a lot of more profound knowledge of mathematics, but she finds that the tasks about lines, triangles, and circles appear less and less. Rikka loves plane geometry because it is simple enough even for a middle school student and is interesting: she misses them very much. So, Rikka wants to come up with some tasks about lines for herself. She draws $n$ lines $y = a_ix+b_i$ on the two-dimensional Cartesian coordinate system. And then she gives a rectangle with the left bottom corner $(x_1,y_1)$ and the right top corner $(x_2,y_2)$. She wants to count the number of the line pairs $(i,j)(i <j)$ which satisfies their cross point (if exists) is inside the rectangle (including the boundary). It is a simple task for Rikka, and she wants to test you. To show your mathematics skill, you need to solve this task as soon as possible. Input The first line contains a single integer $t(1 \leq t \leq 10^3)$, the number of the testcases. For each testcase, the first line contains five single integers $n,x_1,y_1,x_2,y_2$ which satisfy 1$ \leq n \leq 10^5$ and $-10^{9} \leq x_1 < x_2 \leq 10^9, -10^{18} \leq y_1 < y_2 \leq 10^{18}$. And then $n$ lines follow, each line contains two integers $a_i,b_i(-10^9 \leq a_i \leq 10^9, a_i \neq 0, -10^{16} \leq b_i \leq 10^{16})$, describing a line. The input guarantees that each line is unique and there are at most $5$ testcases with $n > 500$. Output For each testcase, output a single line with a single number, the answer. Sample Input
Sample Output
Source | ||||||||||
|