QOJ.ac

QOJ

حد الوقت: 4 s حد الذاكرة: 512 MB مجموع النقاط: 100

#1856. 区间

الإحصائيات

给定 $n$ 个区间,其中第 $j$ 个区间为 $I_j = [l_j, r_j]$。

定义 $[L, R]$ 的“美观度”为 $\bigcup_{i=L}^{R} [l_i, r_i]$ 所覆盖的长度。

给定 $m$ 次查询,第 $i$ 次查询为 $[A_i, B_i]$,你需要回答: 如果我们从所有满足 $A_i \le L_i \le R_i \le B_i$ 的整数对 $(L_i, R_i)$ 中均匀随机采样,那么 $[L_i, R_i]$ 的美观度的期望值是多少?

请输出答案对 $998\,244\,353$ 取模的结果。

输入格式

第一行包含两个整数 $n$ 和 $m$ ($1 \le n, m \le 2 \cdot 10^5$)。

接下来 $n$ 行,每行包含两个整数 $l_j$ 和 $r_j$ ($0 \le l_j < r_j \le 10^8$)。

接下来 $m$ 行,每行包含两个整数 $A_i$ 和 $B_i$ ($1 \le A_i \le B_i \le n$)。

输出格式

输出 $m$ 行,每行包含对应查询的答案,结果对 $998\,244\,353$ 取模。

形式化地,可以证明期望美观度可以表示为一个分数 $p/q$,其中 $p$ 和 $q$ 为互质的非负整数。你需要输出 $p \cdot q^{-1} \pmod{998\,244\,353}$。

样例

样例输入 1

2 1
1 5
4 8
1 2

样例输出 1

5

说明

输入和输出的数据量较大。请记住使用快速输入输出方法,以避免出现“Time Limit Exceeded”。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1393EditorialOpenNew Editorial for Problem #1856_zuoqingyuan2026-04-04 11:39:44View
#531Editorial Open集训队作业 解题报告 by 卢毅奇Qingyu2026-01-02 21:49:46 Download

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.