Grid
题号:NC52769
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 32 M,其他语言64 M
Special Judge, 64bit IO Format: %lld

题目描述

Bobo has points arranged into a matrix with n rows and m columns. The points in the intersection of the i-th row and the j-th column is labeled with (i, j).
He is going to perform q operations of the following 2 kinds.
1. Given parameters a, b, add edges between points (i, j) and (i, j + 1) for all and .
2. Given parameters a, b, add edges between points (i, j) and (i + 1, j) for all and .
Bobo would like to know the number of connected components after each operation.

输入描述:

The input consists of several test cases and is terminated by end-of-file.
The first line of each test case contains three integers n, m and q.
The i-th of the following q lines contains three integers t_i, a_i and b_i where t_i is the kind of the operation i and a_i, b_i are corresponding parameters.

输出描述:

For each test case, print q integers which denote the number of connected components after each operation.
示例1

输入

复制
2 3 3
2 1 1
2 3 3
1 1 1
1000000000 1000000000 1
1 1 2

输出

复制
5
4
2
999999998000000002

备注:

* 
*
*
* If , . If , .
* The sum of q does not exceed .