← Home
write a go solution for Description:
A matrix of size nxm, such that each cell of it contains either 0 or 1, is considered beautiful if the sum in every contiguous submatrix of size 2x2 is exactly 2, i. e. every "square" of size 2x2 contains exactly two 1's and exactly two 0's.

You are given a matrix of size nxm. Initially each cell of this matrix is empty. Let's denote the cell on the intersection of the x-th row and the y-th column as (x,y). You have to process the queries of three types:

- x y -1 — clear the cell (x,y), if there was a number in it;
- x y 0 — write the number 0 in the cell (x,y), overwriting the number that was there previously (if any);
- x y 1 — write the number 1 in the cell (x,y), overwriting the number that was there previously (if any).

After each query, print the number of ways to fill the empty cells of the matrix so that the resulting matrix is beautiful. Since the answers can be large, print them modulo 998244353.

Input Format:
The first line contains three integers n, m and k (2<=n,m<=10^6; 1<=k<=3*10^5) — the number of rows in the matrix, the number of columns, and the number of queries, respectively.

Then k lines follow, the i-th of them contains three integers x_i, y_i, t_i (1<=x_i<=n; 1<=y_i<=m; -1<=t_i<=1) — the parameters for the i-th query.

Output Format:
For each query, print one integer — the number of ways to fill the empty cells of the matrix after the respective query, taken modulo 998244353.

Note:
None. Output only the code with no comments, explanation, or additional text.