Codeforces Round 1097 (Div. 1, Based on Zhili Cup 2026)
F
Zhily and Colorful Strings
Codeforces
3500
原题
← E→
翻译中…

Since Jily's first birthday, Zhily has given him a colored string as a gift each year, and each year's gift has been different from all previous ones. This year, Jily was amazed to discover that he has received every possible distinct gift!

翻译中…

We call a colored string that meets the following conditions valid:

翻译中…
  1. It consists of $m$ types of characters, with exactly $n_i$ characters of the $i$-th type;
  2. Each character of the $i$-th type is colored with one of $c_i$ colors;
  3. The string can be reduced to an empty string by repeatedly deleting $d_i$ consecutive characters of the $i$-th type that share the same color.
翻译中…

Calculate the number of all valid colored strings, modulo $998\,244\,353$.

翻译中…

Two colored strings are considered different if they differ in at least one position (either in character type or in color).

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $m$ ($1\le m\le 2\cdot 10^5$) — the number of types.

翻译中…

The $i$-th of the next $m$ lines contains $n_i, c_i, d_i$ ($1\le c_i \lt 998\,244\,353, 1\le n_i, d_i \le 10^8$) — the total count of characters of the $i$-th type, the number of colors for this type, and the required reduction length, respectively.

翻译中…

It is guaranteed that the sum of $\left\lceil\frac{n_i}{d_i}\right\rceil$ over all test cases does not exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, output one integer in one line, representing the number of valid colored strings, modulo $998\,244\,353$.

翻译中…

Note

翻译中…

For the examples, let's number all the colors by $1, 2, \ldots, \sum_{j=1}^m c_j$. Where the colors $1+\sum_{j=1}^{i-1} c_j,\ldots,\sum_{j=1}^i c_j$ are of the $i$-th type. Below, the color $1, 2, 3$ are colored red, blue, and green, respectively.

翻译中…

For the first test case, the valid strings are:

翻译中…
  1. $[{\color{red}1}, {\color{red}1}, {\color{blue}2}]$
  2. $[{\color{red}1}, {\color{red}1}, {\color{green}3}]$
  3. $[{\color{red}1}, {\color{blue}2}, {\color{red}1}]$
  4. $[{\color{red}1}, {\color{green}3}, {\color{red}1}]$
  5. $[{\color{blue}2}, {\color{red}1}, {\color{red}1}]$
  6. $[{\color{green}3}, {\color{red}1}, {\color{red}1}]$
翻译中…

For any of these strings, we can first remove the only $2$ or $3$, and then remove the $2$ consecutive $1$s.

翻译中…

For the second test case, the valid strings are:

翻译中…
  1. $[{\color{red}1}, {\color{red}1}, {\color{green}3}, {\color{green}3}]$
  2. $[{\color{red}1}, {\color{green}3}, {\color{green}3}, {\color{red}1}]$
  3. $[{\color{blue}2}, {\color{blue}2}, {\color{green}3}, {\color{green}3}]$
  4. $[{\color{blue}2}, {\color{green}3}, {\color{green}3}, {\color{blue}2}]$
  5. $[{\color{green}3}, {\color{red}1}, {\color{red}1}, {\color{green}3}]$
  6. $[{\color{green}3}, {\color{blue}2}, {\color{blue}2}, {\color{green}3}]$
  7. $[{\color{green}3}, {\color{green}3}, {\color{red}1}, {\color{red}1}]$
  8. $[{\color{green}3}, {\color{green}3}, {\color{blue}2}, {\color{blue}2}]$
翻译中…

For the third test case, it can be easily seen that there are no valid strings.

翻译中…

样例

Input #1
3
2
2 1 1
1 2 1
2
2 2 2
2 1 2
2
6 2 3
5 3 2
Output #1
6
8
0
InputCopy OutputCopy
题目信息
题号
2223F
时间限制
7 s
内存限制
512 MB
标签
分治
FFT
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。