Max's Anger Contest Series 2 P5 - Job Anger

View as PDF

Submit solution


Points: 12 (partial)
Time limit: 2.0s
Java 5.0s
Python 5.0s
Memory limit: 1G

Author:
Problem types

After landing his first SWE job, Max is assigned to analyze the data lines on a chiplet.

Specifically, the chiplet has N data lines that are either vertical or horizontal from (x1i,y1i) to (x2i,y2i).

It is known that if two data lines intersect, the data travels slower across both lines.

To determine the inefficiency of a chiplet, Max is told to count the number of intersections between vertical and horizontal data lines.

Two data lines intersect if they are in different directions (one is vertical and one is horizontal) and share one point along both lines.

Further, the start point and end point for a data line are never identical.

Since Max is being sabotaged by Wesley new, all of his code produces Runtime Errors, so he asks you to help him as a co-worker.

Can you help Max count the number of intersections of vertical and horizontal data lines?

Constraints

1N4×105

109x1ix2i109

109y1iy2i109

x1ix2i or y1iy2i

Note that both will NOT be true (i.e. a data line cannot be diagonal).

Subtask 1 [20%]

1N100

100x1i,y1i,x2i,y2i100

Subtask 2 [30%]

100x1i,y1i,x2i,y2i100

Subtask 2 [50%]

No additional constraints.

Input Specification

The first line contains an integer, N, the number of data lines.

The next N lines contain four integers, x1i, y1i, x2i, y2i, the start point and end point of the ith data line.

Output Specification

Output the number of intersections between vertical and horizontal data lines.

Sample Input

Copy
6
0 0 5 0
2 0 9 0
2 0 2 3
2 1 2 5
0 4 3 4
-50 -50 -50 -49

Sample Output

Copy
3

Explanation for Sample

The first and second data lines intersect with the third data line, and the fourth one intersects with the fifth data line.

Note that, despite the first and second data line overlapping, they do not intersect since they are both horizontal.

Likewise, the third and fourth data line overlap but do not intersect since they are both vertical.


Comments

There are no comments at the moment.