#K8676. Count Filled Cells in a Grid
Count Filled Cells in a Grid
Count Filled Cells in a Grid
You are given a grid with m rows and n columns. Initially, the grid is empty. You need to perform a series of k operations. Each operation is described by a pair of integers \(x\) and \(y\), meaning that you fill all cells in the sub-grid from the top-left cell (1, 1) to the cell (x, y) (inclusive).
After performing all the operations, only the cells that have been filled in every operation are considered filled. In other words, the final filled area is the intersection of all the sub-grids described by the operations. Mathematically, if \(x_{min} = \min\{x_i\}\) and \(y_{min} = \min\{y_i\}\) for all operations, then the number of filled cells is given by:
\(\text{Result} = x_{min} \times y_{min}\)
Your task is to compute and output the number of filled cells after performing all operations.
inputFormat
The input is read from standard input (stdin) and is structured as follows:
- The first line contains two integers m and n, representing the number of rows and columns of the grid.
- The second line contains an integer k, the number of operations.
- The following k lines each contain two integers \(x\) and \(y\), representing an operation.
outputFormat
Print a single integer to standard output (stdout): the number of filled cells after all the operations.
## sample3 3
1
2 2
4
</p>