#P11756. Grassland Fence Division
Grassland Fence Division
Grassland Fence Division
Mirko owns a rectangular grassland of width \(A\) meters and height \(B\) meters. The grassland is aligned with the coordinate axes with its lower left corner at \((0,0)\) and its upper right corner at \((A,B)\). Mirko builds fences in two stages: at each operation, he picks a point \((X,Y)\) that is not yet crossed by any fence, and then decides whether to build a horizontal or vertical fence through this point. The fence is built in the chosen direction until it meets an existing fence (or the boundary), thereby splitting one rectangle into two new rectangles. Note that after each operation, the field is partitioned into several rectangles, each having all its edges fenced and no fence inside.
More precisely, if the chosen rectangle has boundaries \(x = L\), \(x = R\), \(y = B_0\) and \(y = T\) (with \(L < X < R\) and \(B_0 < Y .
Your task is: given a series of fence building operations, for each operation determine the areas of the two new rectangles formed, and output them in ascending order.
inputFormat
The first line contains two integers \(A\) and \(B\) (\(1 \leq A, B \leq 10^9\)), which denote the width and height of the grassland.
The second line contains a single integer \(Q\) (\(1 \leq Q \leq 10^5\)), the number of fence operations.
Each of the following \(Q\) lines contains a description of an operation with two integers and a character: \(X\) \(Y\) and \(D\), where \(X\) and \(Y\) (with \(0 < X < A\) and \(0 < Y < B\)) denote the chosen point, and \(D\) is either 'H' or 'V', representing the horizontal or vertical fence respectively.
outputFormat
For each fence operation, output one line containing two integers: the areas of the two newly created rectangles, in ascending order (i.e., from the smaller area to the larger area).
sample
10 6
3
5 3 H
3 5 V
8 1 V
30 30
9 21
6 24
</p>