Count quadruples of red points and pairs of blue points forming an ear shape with angle and containment conditions.
Hard8GeometryBrute forceSortingImplementationNo attempts yetTime limit2sMemory limit512 MBThe coordinate plane holds N red points and M blue points. Every red point has y coordinate 0, and every blue point has a y coordinate greater than 0.
Subin wants to build an ear shape out of these points. An ear shape is made of four distinct red points A, B, C, D and two distinct blue points P, Q, and it must satisfy all three conditions below.
Given the red points and the blue points, write a program that counts the ways to build an ear shape.
Swapping A with D, or B with C, gives the same ear shape. Two ear shapes count as different when they differ in the two points used as A and D, the two points used as B and C, the point P, or the point Q.
The first line contains N and M. (1≤N,M≤300)
The second line contains the x coordinates of the N red points.
Each of the next M lines contains the x coordinate and the y coordinate of one blue point.
Every coordinate in the input is a natural number no greater than 10000. The red points are distinct, and the blue points are distinct.
Print the number of ways to build an ear shape on the first line.
Suppose the red points sit at x=1, x=2, x=6, x=9, and the blue points are (3,1), (6,5), (8,4), (5,3). All four red points are used, so A and D are the points at x=1 and x=9, and B and C are the points at x=2 and x=6. There are four ways to pick P and Q.