Diagonal slices of a rectangle union
Time limit2sMemory limit512 MB
Sum the total length of the union of axis-aligned rectangles cut by each diagonal line y = s - x for integer s in [L, R], and print the result divided by sqrt(2).
- Level
Medium7 of 10
- Topics
- Geometry, Intervals, Prefix sum, Sorting
- Solved
- No attempts yet
Problem
Vera has rectangles whose sides are parallel to the axes. The -th rectangle has opposite corners and . Let be the union of the rectangles.
For a real number , the intersection of with the line is a set of disjoint segments, and some of them may shrink to a single point. Let be the total length of those segments, and let when the intersection is empty.
You are given integers and . Let , where runs over the integers from to . This sum is always for some integer . Find .
Input
The first line contains three integers , , (, ).
Each of the next lines contains four integers , , , (, ).
Output
Print on one line.
Hint
The figure below shows the first example at . There is the total length of the two thick blue segments. For that example .
