Buy Your House
Time limit1sMemory limit128 MB
For each of up to 500 tests with at most 50 non-overlapping axis-aligned houses, count integer-coordinate rectangles that contain exactly one house and split none, modulo 1e9+7.
- Level
Hard8 of 10
- Topics
- Geometry, Combinatorics, Math, Brute force
- Solved
- No attempts yet
Problem
You want to buy a house, so you contact a real estate company that has just started its business — and you will be their very first customer. Because of that, they make you a special offer.
The company owns a single rectangular plot of land of width and height . Positions use a coordinate system whose origin is the lower-left corner of the plot: a point that lies units to the right and units up from that corner is written as , so every point of the plot satisfies and .
Several houses have already been built on the plot. Each house is an axis-aligned rectangle whose edges are parallel to the edges of the plot, and no two houses overlap. A house is described by four integers , where is its lower-left corner and its upper-right corner.
The special offer works like this: you may pick any axis-aligned rectangular region of the plot that contains exactly one house, together with as much (or as little) surrounding open space as you like. If you only want the land the house stands on, you may take exactly that; if you can afford more, you may keep some open space around it — a garden, for example.
The region you choose must obey these rules:
- Its edges must be parallel to the edges of the plot, and all four corners must be at integer coordinates (for example is allowed, but is not).
- No house may be split by the region's boundary: every house is either completely inside your region or completely outside it.
- The region must contain exactly one house — never zero houses, and never two or more.
How many different regions can you choose?
Input
The first line contains an integer (about ), the number of test cases.
Each test case begins with a line containing two integers and (), the width and height of the plot. The next line contains an integer (), the number of houses. Each of the following lines contains four integers ( and ) describing one house. No two houses overlap, and all coordinates are non-negative integers.
Output
For each test case, print a single line in the form Case k: A, where k is the test case number (starting from ) and A is the number of regions you can choose. Because this number can be very large, print it modulo .