#P2956. Robotic Plow

    ID: 16214 Type: Default 1000ms 256MiB

Robotic Plow

Robotic Plow

A farmer has purchased a new robotic plow that can plow rectangular regions with integer side lengths. However, each plowing instruction defines a rectangle by its lower-left and upper-right coordinates, and these rectangular plowings might overlap. Your task is to determine the total number of unique squares that get plowed.

Each rectangle is defined by coordinates \( (X_{ll}, Y_{ll}) \) and \( (X_{ur}, Y_{ur}) \), and includes all squares such that \(X_{ll} \leq x \leq X_{ur}\) and \(Y_{ll} \leq y \leq Y_{ur}\). Note that the number of columns in the rectangle is given by \(X_{ur} - X_{ll} + 1\) and the number of rows by \(Y_{ur} - Y_{ll} + 1\).

Overlapping areas are only counted once.

inputFormat

The first line contains three integers: X, Y, and I, representing the field's width, the field's height, and the number of plowing instructions, respectively. The field is divided into X columns and Y rows of unit squares.

Each of the following I lines contains four integers: Xll, Yll, Xur, and Yur. These represent the lower-left and upper-right coordinates of a rectangle to be plowed (inclusive).

outputFormat

Output a single integer representing the total number of unique squares that have been plowed at least once.

sample

6 4 2
1 1 2 4
1 3 5 4
14

</p>