G |
Super
Rooks on a Chessboard Input: Standard Input Output: Standard Output |
Let's assume there is a new
chess piece named Super-rook. When
placed at a cell of a chessboard, it attacks all the cells that belong to the same row or same column. Additionally it attacks all the cells of the diagonal that goes from top-left to bottom-right direction through that cell.
N Super-rooks are
placed on a R x C chessboard. The
rows are numbered 1 to R from top to bottom and columns are
numbered 1 to C from left to right of the chessboard. You have to find the number
of cells of the chessboard which are not
attacked by any of the Super-rooks.
The picture on the left shows the
attacked cells when a Super-rook is placed at cell (5, 3) of a 6 x 6
chessboard. And the picture on the right shows the attacked cells when three
Super-rooks are placed at cells (3, 4) , (5, 3) and (5, 6). These pictures
(Left and right one) corresponds to the first and second sample input
respectively.
First line of input contains an integer T(1 ≤ T ≤ 20) which is the number of test cases. The first line of each test case contains three integers R, C and N( 1 ≤ R, C, N ≤ 50,000 ). The next N lines contain two integers r, c giving the row and column of a Super-rook on the chessboard (1 ≤ r ≤ R and 1 ≤ c ≤ C). You may assume that two Super-rooks won’t be placed on the same cell.
For each test case, output the case number
followed by the number of cells which are not
attacked by any of the Super-rook.
2 6 6 1 5 3 6 6 3 3 4 5 3 5 6 |
Case 1: 22 Case 2: 9 |
Problemsetter: Tasnim Imran Sunny, Special Thanks: Md. Mahbubul Hasan