#P9737. Counting Good Subrectangles
Counting Good Subrectangles
Counting Good Subrectangles
Teo's balcony is a rectangular platform with dimensions \(n+1\) by \(m+1\) (its bottom‐left corner is at \((0,0)\) and its top‐right corner is at \((n,m)\)). There are \(2k\) colored lights on the balcony, two for each color numbered from \(1\) to \(k\). Each light is located at a point with positive integer coordinates.
A subrectangle of the balcony is defined by choosing two distinct vertical grid lines and two distinct horizontal grid lines such that:
- The subrectangle’s sides are parallel to the balcony sides.
- The coordinates of its bottom‐left and top‐right corners are integers.
- Its width and height are at least \(2\) (i.e. if the bottom–left is \((x_1,y_1)\) and the top–right is \((x_2,y_2)\), then \(x_2-x_1\ge2\) and \(y_2-y_1\ge2\)).
- For every color, the two lights of that color are either both inside or both outside the subrectangle. A light is considered to be inside a subrectangle if it lies within or on the boundary of the subrectangle.
Find the number of good subrectangles on the balcony.
Note: The balcony spans from \((0,0)\) to \((n,m)\).
inputFormat
The first line contains three integers \(n\), \(m\) and \(k\).
Each of the next \(k\) lines contains four integers \(x_1\), \(y_1\), \(x_2\) and \(y_2\), representing the coordinates of the two lights of one color. All light coordinates are positive integers.
outputFormat
Output a single integer, the number of good subrectangles.
sample
3 3 1
1 1 2 2
9
</p>