CF2056E.Nested Segments

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

A set AA consisting of pairwise distinct segments [l,r][l, r] with integer endpoints is called good if 1≤l≤r≤n1\le l\le r\le n, and for any pair of distinct segments [li,ri],[lj,rj][l_i, r_i], [l_j, r_j] in AA, exactly one of the following conditions holds:

  • ri<ljr_i \lt l_j or rj<lir_j \lt l_i (the segments do not intersect)
  • li≤lj≤rj≤ril_i \le l_j \le r_j \le r_i or lj≤li≤ri≤rjl_j \le l_i \le r_i \le r_j (one segment is fully contained within the other)

You are given a good set SS consisting of mm pairwise distinct segments [li,ri][l_i, r_i] with integer endpoints. You want to add as many additional segments to the set SS as possible while ensuring that set SS remains good.

Since this task is too easy, you need to determine the number of different ways to add the maximum number of additional segments to SS, ensuring that the set remains good. Two ways are considered different if there exists a segment that is being added in one of the ways, but not in the other.

Formally, you need to find the number of good sets TT of distinct segments, such that SS is a subset of TT and TT has the maximum possible size. Since the result might be very large, compute the answer modulo 998 244 353998\,244\,353.

一个由两两互异的整数端点线段 [l,r][l, r] 构成的集合 AA 被称为好集合,若其满足:1≤l≤r≤n1\le l\le r\le n,且对 AA 中任意两个互异的线段 [li,ri],[lj,rj][l_i, r_i], [l_j, r_j],以下条件中恰好有一个成立:

  • ri<ljr_i \lt l_j 或 rj<lir_j \lt l_i(两线段不相交);
  • li≤lj≤rj≤ril_i \le l_j \le r_j \le r_i 或 lj≤li≤ri≤rjl_j \le l_i \le r_i \le r_j(其中一个线段完全包含于另一个线段之内)。

现给定一个大小为 mm 的好集合 SS,其中包含 mm 个两两互异的整数端点线段 [li,ri][l_i, r_i]。你希望向集合 SS 中添加尽可能多的额外线段,同时保证添加后所得集合仍为好集合。

但本题难度略低,因此你需要计算:在保证集合仍为好集合的前提下,添加最大可能数量的额外线段的不同方案数。若存在某个线段,在一种方案中被添加、而在另一种方案中未被添加,则认为这两种方案不同。

形式化地,你需要计算满足如下条件的好集合 TT(其元素均为互异线段)的个数:S⊆TS \subseteq T,且 TT 具有最大可能的大小。由于答案可能非常大,请将结果对 998 244 353998\,244\,353 取模。

输入格式

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

The first line of each test case contains two integers nn and mm (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5, 0≤m≤2⋅1050 \le m \le 2 \cdot 10^5) — the maximum right endpoint of the segments, and the size of SS.

The ii-th of the next mm lines contains two integers lil_i and rir_i (1≤li≤ri≤n1 \le l_i \le r_i \le n) — the boundaries of the segments in set SS.

It is guaranteed that the given set SS is good, and the segments in set SS are pairwise distinct.

It is guaranteed that both the sum of nn and the sum of mm over all test cases do not exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5,0≤m≤2⋅1050 \le m \le 2 \cdot 10^5)——分别表示线段右端点的最大值,以及集合 SS 的大小。

接下来的 mm 行中,第 ii 行包含两个整数 lil_i 和 rir_i(1≤li≤ri≤n1 \le l_i \le r_i \le n)——表示集合 SS 中第 ii 条线段的左右端点。

保证所给集合 SS 是“好”的,且集合 SS 中的线段两两互不相同。

保证所有测试用例中 nn 的总和与 mm 的总和均不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output a single integer representing the number of different ways, modulo 998 244 353998\,244\,353, that you can add the maximum number of additional segments to set SS while ensuring that set SS remains good.

对于每个测试用例,输出一个整数,表示在保证集合 SS 仍为“好集合”的前提下,向集合 SS 中添加最多数量的额外线段的不同方案数,结果对 998 244 353998\,244\,353 取模。

输入输出样例

  • 输入#1

    6
    1 0
    2 3
    1 1
    2 2
    1 2
    5 2
    1 3
    2 3
    4 1
    1 1
    6 2
    1 3
    4 6
    2300 0

    输出#1

    1
    1
    2
    5
    4
    187997613

说明/提示

In the first example, the only possible segment is [1,1][1, 1], so T=[1,1]T = {[1, 1]} has the maximum size, and it is the only solution.

In the second example, it is not possible to add any additional segments to set SS. Hence, the only way to add segments to SS is adding nothing.

In the third example, it is possible to add 77 additional segments to SS while ensuring that the set remains good. It can be proven that adding more than 77 additional segments to SS is not possible. There are exactly 22 different ways to add these 77 segments to SS, and their respective sets TT are shown below:

  • [1,1],[1,3],[1,4],[1,5],[2,2],[2,3],[3,3],[4,4],[5,5]{[1, 1], [1, 3], [1, 4], [1, 5], [2, 2], [2, 3], [3, 3], [4, 4], [5, 5]}
  • [1,1],[1,3],[1,5],[2,2],[2,3],[3,3],[4,4],[4,5],[5,5]{[1, 1], [1, 3], [1, 5], [2, 2], [2, 3], [3, 3], [4, 4], [4, 5], [5, 5]}.

In the fourth example, there are exactly 55 different ways to add a maximum of 66 additional segments to SS, and their respective sets TT are shown below:

  • [1,1],[1,2],[1,3],[1,4],[2,2],[3,3],[4,4]{[1, 1], [1, 2], [1, 3], [1, 4], [2, 2], [3, 3], [4, 4]}
  • [1,1],[1,2],[1,4],[2,2],[3,3],[3,4],[4,4]{[1, 1], [1, 2], [1, 4], [2, 2], [3, 3], [3, 4], [4, 4]}
  • [1,1],[1,3],[1,4],[2,2],[2,3],[3,3],[4,4]{[1, 1], [1, 3], [1, 4], [2, 2], [2, 3], [3, 3], [4, 4]}
  • [1,1],[1,4],[2,2],[2,3],[2,4],[3,3],[4,4]{[1, 1], [1, 4], [2, 2], [2, 3], [2, 4], [3, 3], [4, 4]}
  • [1,1],[1,4],[2,2],[2,4],[3,3],[3,4],[4,4]{[1, 1], [1, 4], [2, 2], [2, 4], [3, 3], [3, 4], [4, 4]}

在第一个例子中,唯一可能的线段是 [1,1][1, 1],因此 T=[1,1]T = {[1, 1]} 具有最大大小,且是唯一的解。

在第二个例子中,无法向集合 SS 中添加任何额外的线段。因此,向 SS 中添加线段的唯一方式是不添加任何线段。

在第三个例子中,可以在保证集合仍为“好集合”的前提下,向 SS 中添加 77 条额外的线段。可以证明:向 SS 中添加超过 77 条额外线段是不可能的。恰好存在 22 种不同的方式来向 SS 中添加这 77 条线段,它们各自对应的集合 TT 如下所示:

  • [1,1],[1,3],[1,4],[1,5],[2,2],[2,3],[3,3],[4,4],[5,5]{[1, 1], [1, 3], [1, 4], [1, 5], [2, 2], [2, 3], [3, 3], [4, 4], [5, 5]}
  • [1,1],[1,3],[1,5],[2,2],[2,3],[3,3],[4,4],[4,5],[5,5]{[1, 1], [1, 3], [1, 5], [2, 2], [2, 3], [3, 3], [4, 4], [4, 5], [5, 5]}

在第四个例子中,恰好存在 55 种不同的方式,向 SS 中添加最多 66 条额外线段,它们各自对应的集合 TT 如下所示:

  • [1,1],[1,2],[1,3],[1,4],[2,2],[3,3],[4,4]{[1, 1], [1, 2], [1, 3], [1, 4], [2, 2], [3, 3], [4, 4]}
  • [1,1],[1,2],[1,4],[2,2],[3,3],[3,4],[4,4]{[1, 1], [1, 2], [1, 4], [2, 2], [3, 3], [3, 4], [4, 4]}
  • [1,1],[1,3],[1,4],[2,2],[2,3],[3,3],[4,4]{[1, 1], [1, 3], [1, 4], [2, 2], [2, 3], [3, 3], [4, 4]}
  • [1,1],[1,4],[2,2],[2,3],[2,4],[3,3],[4,4]{[1, 1], [1, 4], [2, 2], [2, 3], [2, 4], [3, 3], [4, 4]}
  • [1,1],[1,4],[2,2],[2,4],[3,3],[3,4],[4,4]{[1, 1], [1, 4], [2, 2], [2, 4], [3, 3], [3, 4], [4, 4]}

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

首页