CF1830C.Hyperregular Bracket Strings

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an integer nn and kk intervals. The ii-th interval is [li,ri][l_i,r_i] where 1≤li≤ri≤n1 \leq l_i \leq r_i \leq n.

Let us call a regular bracket sequence†,‡^{\dagger,\ddagger} of length nn hyperregular if for each ii such that 1≤i≤k1 \leq i \leq k, the substring slisli+1…sri‾\overline{s_{l_i} s_{l_{i}+1} \ldots s_{r_i}} is also a regular bracket sequence.

Your task is to count the number of hyperregular bracket sequences. Since this number can be really large, you are only required to find it modulo 998 244 353998\,244\,353.

†^\dagger A bracket sequence is a string containing only the characters "(" and ")".

‡^\ddagger A bracket sequence is called regular if one can turn it into a valid math expression by adding characters + and 1. For example, sequences (())(), (), (()(())) and the empty string are regular, while )(, ((), and (()))( are not.

给你一个整数 nn 和 kk 个区间。第 ii 个区间为 [li,ri][l_i,r_i],其中 1≤li≤ri≤n1 \leq l_i \leq r_i \leq n。

我们称一个长度为 nn 的正规括号序列†,‡^{\dagger,\ddagger} 是超正规的,如果对每个满足 1≤i≤k1 \leq i \leq k 的 ii,子串 slisli+1…sri‾\overline{s_{l_i} s_{l_{i}+1} \ldots s_{r_i}} 本身也是一个正规括号序列。

你的任务是计算超正规括号序列的个数。由于该数目可能非常大,你只需输出其对 998 244 353998\,244\,353 取模的结果。

†^\dagger 括号序列是指仅由字符 "(" 和 ")" 组成的字符串。

‡^\ddagger 若一个括号序列可通过添加字符 "+" 和 "1" 而变成一个合法的数学表达式,则称其为正规的。例如,序列 (())(), (), (()(())) 以及空串是正规的,而 )(、(() 和 (()))( 则不是。

输入格式

Each test contains multiple test cases. The first line of input contains a single integer tt (1≤t≤1051 \le t \le 10^5) — the number of test cases. The description of test cases follows.

The first line of each test case contains two integers nn and kk (1≤n≤3⋅1051 \le n \le 3 \cdot 10^5, 0≤k≤3⋅1050 \le k \le 3 \cdot 10^5) — the length of the hyperregular bracket sequences and the number of intervals respectively.

The following kk lines of each test case contains two integers lil_i and rir_i (1≤l≤r≤n1 \le l \le r \le n).

It is guaranteed that the sum of nn across all test cases does not exceed 3⋅1053 \cdot 10^5 and the sum of kk across all test cases does not exceed 3⋅1053 \cdot 10^5.

每个测试包含多个测试用例。输入的第一行包含一个整数 tt(1≤t≤1051 \le t \le 10^5),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 kk(1≤n≤3⋅1051 \le n \le 3 \cdot 10^5,0≤k≤3⋅1050 \le k \le 3 \cdot 10^5),分别表示超正则括号序列的长度和区间的数量。

每个测试用例的接下来 kk 行,每行包含两个整数 lil_i 和 rir_i(1≤li≤ri≤n1 \le l_i \le r_i \le n)。

保证所有测试用例中 nn 的总和不超过 3⋅1053 \cdot 10^5,且所有测试用例中 kk 的总和不超过 3⋅1053 \cdot 10^5。

输出格式

For each test case, output the number of hyperregular bracket sequences modulo 998 244 353998\,244\,353.

对于每个测试用例,输出超正则括号序列的数量对 998 244 353998\,244\,353 取模的结果。

输入输出样例

  • 输入#1

    7
    6 0
    5 0
    8 1
    1 3
    10 2
    3 4
    6 9
    1000 3
    100 701
    200 801
    300 901
    28 5
    1 12
    3 20
    11 14
    4 9
    18 19
    4 3
    1 4
    1 4
    1 4

    输出#1

    5
    0
    0
    4
    839415253
    140
    2

说明/提示

  • For the first testcase, the 55 hyperregular bracket strings of length 66 are: ((())), (()()), (())(), ()(()) and ()()().

  • For the second testcase, there are no regular bracket strings of length 55, and consequently, there are no hyperregular bracket strings of length 55.

  • For the third testcase, there are no hyperregular bracket strings of length 88 for which the substring [1…3][1 \ldots 3] is a regular bracket string.

  • For the fourth testcase, there 44 hyperregular bracket strings are: ((())(())), ((())()()), ()()((())) and ()()(()())

  • 对于第一个测试用例,长度为 66 的 55 个超正则括号串为:((())), (()()), (())(), ()(()) 和 ()()()。

  • 对于第二个测试用例,不存在长度为 55 的正则括号串,因此也不存在长度为 55 的超正则括号串。

  • 对于第三个测试用例,不存在长度为 88 的超正则括号串,使得其子串 [1…3][1 \ldots 3] 是一个正则括号串。

  • 对于第四个测试用例,存在 44 个超正则括号串:((())(())), ((())()()), ()()((())) 和 ()()(()())。

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

首页