QOJ.ac

QOJ

時間限制: 2.0 s 記憶體限制: 512 MB 總分: 100

#9323. 线段与子集

统计

考虑坐标轴上的一组线段。端点的坐标是 $0$ 到 $x$ 之间的整数。不存在相交的线段对:对于任意两条线段,要么其中一条包含另一条,要么它们最多只有一个公共点。

你的目标是将这组线段转换为唯一的线段 $[0, x]$,且不能有其他线段剩余。为了达到这个目标,你可以进行以下类型的操作:

  • 选择两条具有唯一公共点的线段:左侧线段的右端点与右侧线段的左端点重合。将它们合并为一条线段:从最左端点到最右端点。此操作不消耗任何代价。
  • 选择一条线段。将其向左或向右扩展 $1$ 个单位。此操作消耗 $1$ 枚硬币。

如果在任何时刻存在两条或多条相同的线段,则仅保留其中一条,其余的立即消失。

对于初始线段集合 $S$,令 $F(S)$ 为将其转换为唯一的线段 $[0, x]$ 所需的最小硬币数量。给定一个包含 $n$ 条线段的集合,考虑其所有 $2^n - 1$ 个非空子集,计算每个子集的 $F$ 值,并求出这些值的总和,结果对 $998\,244\,353$ 取模。

输入格式

第一行包含一个整数 $t$ ($1 \le t \le 10^5$),表示测试用例的数量。接下来是各测试用例。

每个测试用例的第一行包含两个整数:线段数量 $n$ ($1 \le n \le 10^5$) 和坐标 $x$ ($1 \le x \le 10^9$)。接下来的 $n$ 行描述这些线段。第 $i$ 行包含两个整数 $\ell_i$ 和 $r_i$,表示第 $i$ 条线段的端点 ($0 \le \ell_i < r_i \le x$)。

所有测试用例的 $n$ 之和不超过 $10^5$。

输出格式

对于每个测试用例,输出一行,包含一个整数,表示所求总和对 $998\,244\,353$ 取模的结果。

样例

样例输入 1

3
2 5
1 4
2 3
3 8
1 3
3 5
5 8
7 10
1 5
2 3
3 4
4 5
5 10
6 9
7 8

样例输出 1

10
28
806

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.