CF1933G.Turtle Magic: Royal Turtle Shell Pattern

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Turtle Alice is currently designing a fortune cookie box, and she would like to incorporate the theory of LuoShu into it.

The box can be seen as an n×mn \times m grid (n,m≥5n, m \ge 5), where the rows are numbered 1,2,…,n1, 2, \dots, n and columns are numbered 1,2,…,m1, 2, \dots, m. Each cell can either be empty or have a single fortune cookie of one of the following shapes: circle or square. The cell at the intersection of the aa-th row and the bb-th column is denoted as (a,b)(a, b).

Initially, the entire grid is empty. Then, Alice performs qq operations on the fortune cookie box. The ii-th operation (1≤i≤q1 \le i \le q) is as follows: specify a currently empty cell (ri,ci)(r_i,c_i) and a shape (circle or square), then put a fortune cookie of the specified shape on cell (ri,ci)(r_i,c_i). Note that after the ii-th operation, the cell (ri,ci)(r_i,c_i) is no longer empty.

Before all operations and after each of the qq operations, Alice wonders what the number of ways to place fortune cookies in all remaining empty cells is, such that the following condition is satisfied:

No three consecutive cells (in horizontal, vertical, and both diagonal directions) contain cookies of the same shape. Formally:

  • There does not exist any (i,j)(i,j) satisfying 1≤i≤n,1≤j≤m−21 \le i \le n, 1 \le j \le m-2, such that there are cookies of the same shape in cells (i,j),(i,j+1),(i,j+2)(i,j), (i,j+1), (i,j+2).
  • There does not exist any (i,j)(i,j) satisfying 1≤i≤n−2,1≤j≤m1 \le i \le n-2, 1 \le j \le m, such that there are cookies of the same shape in cells (i,j),(i+1,j),(i+2,j)(i,j), (i+1,j), (i+2,j).
  • There does not exist any (i,j)(i,j) satisfying 1≤i≤n−2,1≤j≤m−21 \le i \le n-2, 1 \le j \le m-2, such that there are cookies of the same shape in cells (i,j),(i+1,j+1),(i+2,j+2)(i,j), (i+1,j+1), (i+2,j+2).
  • There does not exist any (i,j)(i,j) satisfying 1≤i≤n−2,1≤j≤m−21 \le i \le n-2, 1 \le j \le m-2, such that there are cookies of the same shape in cells (i,j+2),(i+1,j+1),(i+2,j)(i,j+2), (i+1,j+1), (i+2,j).

You should output all answers modulo 998 244 353998\,244\,353. Also note that it is possible that after some operations, the condition is already not satisfied with the already placed candies, in this case you should output 00.

海龟爱丽丝正在设计一款幸运饼干盒,并希望将洛书理论融入其中。

该盒子可视为一个 n×mn \times m 的网格(其中 n,m≥5n, m \ge 5),行编号为 1,2,…,n1, 2, \dots, n,列编号为 1,2,…,m1, 2, \dots, m。每个格子要么为空,要么放置一枚幸运饼干,其形状为圆形或方形之一。第 aa 行与第 bb 列交叉处的格子记为 (a,b)(a, b)。

初始时,整个网格为空。随后,爱丽丝对幸运饼干盒执行 qq 次操作。第 ii 次操作(1≤i≤q1 \le i \le q)如下:指定一个当前为空的格子 (ri,ci)(r_i,c_i) 和一种形状(圆形或方形),然后在格子 (ri,ci)(r_i,c_i) 上放置一枚指定形状的幸运饼干。注意,第 ii 次操作完成后,格子 (ri,ci)(r_i,c_i) 不再为空。

在所有操作开始前,以及每次操作结束后,爱丽丝都想知道:在所有剩余空格子中放置幸运饼干(每格至多一枚,形状为圆形或方形),使得以下条件成立的方案数是多少?

任意三个连续格子(水平、垂直及两个对角线方向)均不能同时包含同一种形状的饼干。形式化地:

  • 不存在满足 1≤i≤n, 1≤j≤m−21 \le i \le n,\, 1 \le j \le m-2 的 (i,j)(i,j),使得格子 (i,j), (i,j+1), (i,j+2)(i,j),\, (i,j+1),\, (i,j+2) 均含有同一种形状的饼干;
  • 不存在满足 1≤i≤n−2, 1≤j≤m1 \le i \le n-2,\, 1 \le j \le m 的 (i,j)(i,j),使得格子 (i,j), (i+1,j), (i+2,j)(i,j),\, (i+1,j),\, (i+2,j) 均含有同一种形状的饼干;
  • 不存在满足 1≤i≤n−2, 1≤j≤m−21 \le i \le n-2,\, 1 \le j \le m-2 的 (i,j)(i,j),使得格子 (i,j), (i+1,j+1), (i+2,j+2)(i,j),\, (i+1,j+1),\, (i+2,j+2) 均含有同一种形状的饼干;
  • 不存在满足 1≤i≤n−2, 1≤j≤m−21 \le i \le n-2,\, 1 \le j \le m-2 的 (i,j)(i,j),使得格子 (i,j+2), (i+1,j+1), (i+2,j)(i,j+2),\, (i+1,j+1),\, (i+2,j) 均含有同一种形状的饼干。

你应输出所有答案对 998 244 353998\,244\,353 取模的结果。另外请注意:在某些操作之后,已放置的饼干可能已违反上述条件,此时应输出 00。

输入格式

The first line of the input contains a single integer tt (1≤t≤1031 \le t \le 10^3) — the number of test cases.

The first line of each test case contains three integers nn, mm, qq (5≤n,m≤109,0≤q≤min⁡(n×m,105)5 \le n, m \le 10^9, 0 \le q \le \min(n \times m, 10^5)).

The ii-th of the next qq lines contains two integers rir_i, cic_i and a single string shapei\text{shape}_i (1≤ri≤n,1≤ci≤m1 \le r_i \le n, 1 \le c_i \le m, shapei=\text{shape}_i= "circle" or "square"), representing the operations. It is guaranteed that the cell on the rir_i-th row and the cic_i-th column is initially empty. That means, each (ri,ci)(r_i,c_i) will appear at most once in the updates.

The sum of qq over all test cases does not exceed 10510^5.

输入的第一行包含一个整数 tt(1≤t≤1031 \le t \le 10^3),表示测试用例的数量。

每个测试用例的第一行包含三个整数 nn、mm、qq(5≤n,m≤1095 \le n, m \le 10^9,0≤q≤min⁡(n×m,105)0 \le q \le \min(n \times m, 10^5))。

接下来的 qq 行中,第 ii 行包含两个整数 rir_i、cic_i 和一个字符串 shapei\text{shape}_i(1≤ri≤n1 \le r_i \le n,1≤ci≤m1 \le c_i \le m,shapei=\text{shape}_i = "circle" 或 "square"),表示一次操作。保证第 rir_i 行第 cic_i 列的格子初始为空,即每对 (ri,ci)(r_i,c_i) 在所有更新中至多出现一次。

所有测试用例的 qq 值之和不超过 10510^5。

输出格式

For each test case, output q+1q+1 lines. The first line of each test case should contain the answer before any operations. The ii-th line (2≤i≤q+12 \le i \le q+1) should contain the answer after the first i−1i-1 operations. All answers should be taken modulo 998 244 353998\,244\,353.

对于每个测试用例,输出 q+1q+1 行。每个测试用例的第一行应包含所有操作执行前的答案。第 ii 行(2≤i≤q+12 \le i \le q+1)应包含执行前 i−1i-1 次操作后的答案。所有答案均需对 998 244 353998\,244\,353 取模。

输入输出样例

  • 输入#1

    2
    6 7 4
    3 3 circle
    3 6 square
    5 3 circle
    5 4 square
    5 5 3
    1 1 circle
    1 2 circle
    1 3 circle

    输出#1

    8
    4
    3
    1
    0
    8
    4
    1
    0

说明/提示

In the second sample, after placing a circle-shaped fortune cookie to cells (1,1)(1,1), (1,2)(1,2) and (1,3)(1,3), the condition is already not satisfied. Therefore, you should output 00.

在第二个样例中,将圆形幸运饼干放置在单元格 (1,1)(1,1)、(1,2)(1,2) 和 (1,3)(1,3) 后,条件已不再满足。因此,你应该输出 00。

输入解题思路,AI测评打分。不知道怎么写?

首页