CF1574E.Coloring

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A matrix of size n×mn \times m , such that each cell of it contains either 00 or 11 , is considered beautiful if the sum in every contiguous submatrix of size 2×22 \times 2 is exactly 22 , i. e. every "square" of size 2×22 \times 2 contains exactly two 11 's and exactly two 00 's.

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

  • xx yy 1-1 — clear the cell (x,y)(x, y) , if there was a number in it;
  • xx yy 00 — write the number 00 in the cell (x,y)(x, y) , overwriting the number that was there previously (if any);
  • xx yy 11 — write the number 11 in the cell (x,y)(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 998244353998244353 .

输入格式

The first line contains three integers nn , mm and kk ( 2n,m1062 \le n, m \le 10^6 ; 1k31051 \le k \le 3 \cdot 10^5 ) — the number of rows in the matrix, the number of columns, and the number of queries, respectively.

Then kk lines follow, the ii -th of them contains three integers xix_i , yiy_i , tit_i ( 1xin1 \le x_i \le n ; 1yim1 \le y_i \le m ; 1ti1-1 \le t_i \le 1 ) — the parameters for the ii -th query.

输出格式

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

输入输出样例

  • 输入#1

    2 2 7
    1 1 1
    1 2 1
    2 1 1
    1 1 0
    1 2 -1
    2 1 -1
    1 1 -1

    输出#1

    3
    1
    0
    1
    2
    3
    6
首页