問題一覧 > 通常問題

No.3146 RE: Parentheses Counting

レベル : / AI推定難易度 : 2000 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 33
作問者 : nauclhlt / テスター : 👑 p-adic
お気に入りにしたユーザー ProblemId : 12025 / 自分の提出
問題文最終更新日: 2025-05-15 08:31:10
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 467 (順位表) の他の問題:

Story

It seems $N$ is large this time.

Problem Statement

Definition of a balanced parenthesis sequence

A string $X$ is a balanced parenthesis sequence if it satisfies the following.

  • $X$ can be made into the empty string by repeating, $0$ or more times, the operation of deleting a () contained in $X$ as a substring

For example, ()(()) and ()()()() are balanced parenthesis sequences, but ))(( and )()()( are not balanced parenthesis sequences.


For a balanced parenthesis sequence $T$, let $f(T)$ be the value of $x$ after performing the following procedure.

  • Initially, let $S$ be the empty set and $x=0$, and do the following for $i=1, 2, \cdots, N$ in this order.
    • If $T_i=$(, add $i$ to $S$.
    • If $T_i=$), let $j$ be the largest element contained in $S$, and add to $x$ the number of occurrences of () as a substring in the string obtained by extracting the open interval $(j, i)$ of $T$. Then, remove $j$ from $S$.

For example, $f($()(())$)=1, f($(()()())$)=3$.

You are given a positive integer $N$. Find the sum of $f(S)$ over all possible strings that are balanced parenthesis sequences $S$ of length $N$.
Since the answer can be very large, find it modulo $998244353$.

You are given $T$ cases; answer each of them.

Notation for strings For a string $A$, let $|A|$ be the length of $A$. Then $A_i(1\leq i\leq |A|)$ denotes the $i$-th character of $A$.

Input

$T$
$case_1$
$case_2$
$\vdots$
$case_T$

$case_i$ represents the $i$-th case and is given in the following format.

$N$
  • $1\leq T\leq 10^5$
  • For each case, $1\leq N\leq 10^6$

Output

Output $T$ lines. On the $k(1\leq k\leq T)$-th line, output the answer for the $k$-th case.
For each case, let $r$ be the sum of $f(S)$ modulo $998244353$, and output it in the following format.

$r$

Print a newline at the end.

Sample

Sample 1
Input
3
4
2
11
Output
1
0
0

For example, in the 1st case, the balanced parenthesis sequences of length $4$ are the 2 strings ()() and (()). Since $f($()()$)=0, f($(())$)=1$, output 1.

In the 3rd case, no balanced parenthesis sequence of length $11$ exists. Therefore, output 0.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。