CF1830C.Hyperregular Bracket Strings
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an integer n and k intervals. The i -th interval is [li,ri] where 1≤li≤ri≤n .
Let us call a regular bracket sequence †,‡ of length n hyperregular if for each i such that 1≤i≤k , the substring slisli+1…sri 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 998244353 .
† A bracket sequence is a string containing only the characters "(" and ")".
‡ 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.
输入格式
Each test contains multiple test cases. The first line of input contains a single integer t ( 1≤t≤105 ) — the number of test cases. The description of test cases follows.
The first line of each test case contains two integers n and k ( 1≤n≤3⋅105 , 0≤k≤3⋅105 ) — the length of the hyperregular bracket sequences and the number of intervals respectively.
The following k lines of each test case contains two integers li and ri ( 1≤l≤r≤n ).
It is guaranteed that the sum of n across all test cases does not exceed 3⋅105 and the sum of k across all test cases does not exceed 3⋅105 .
输出格式
For each test case, output the number of hyperregular bracket sequences modulo 998244353 .
输入输出样例
输入#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 5 hyperregular bracket strings of length 6 are: ((())), (()()), (())(), ()(()) and ()()().
- For the second testcase, there are no regular bracket strings of length 5 , and consequently, there are no hyperregular bracket strings of length 5 .
- For the third testcase, there are no hyperregular bracket strings of length 8 for which the substring [1…3] is a regular bracket string.
- For the fourth testcase, there 4 hyperregular bracket strings are: ((())(())), ((())()()), ()()((())) and ()()(()())