Cutting Lines
Time limit3sMemory limit256 MB
Count the pieces of a W by H rectangle after cutting along N axis-parallel interior segments.
- Level
Medium7 of 10
- Topics
- Geometry, Union-find, Sorting, Math
- Solved
- No attempts yet
Problem
A rectangle has corners , , , and . There are cut segments, each parallel to a side. Segment runs from to with exactly one of or . Parallel segments never share a point, and no parallel segment touches the paper border. After cutting along every segment, how many pieces remain?
Input
The first line has , , and . The next lines give each segment's endpoints.
Output
Print the number of pieces on one line.
Limits
, .