D. Many Segments 2

    Type: Default 1000ms 256MiB

Many Segments 2

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

AT_abc377_d [ABC377D] Many Segments 2

题目描述

给定长度为 NN 的正整数列 L=(L1,L2,,LN),R=(R1,R2,,RN)L=(L_1,L_2,\ldots,L_N),R=(R_1,R_2,\ldots,R_N) 和整数 MM

求同时满足以下条件的整数组 (l,r)(l,r) 的个数。

  • 1lrM1\le l\le r\le M

  • 对于所有 1iN1\le i\le N,区间 [l,r][l,r] 不完全包含区间 [Li,Ri]\left[L_i,R_i\right]

输入格式

输入按照如下标准给出:

NN MM
L1L_1 R1R_1
L2L_2 R2R_2
\vdots
LNL_N RNR_N

输出格式

输出答案即可。

输入输出样例 #1

输入 #1

2 4
1 2
3 4

输出 #1

5

输入输出样例 #2

输入 #2

6 5
1 1
2 2
3 3
4 4
5 5
1 5

输出 #2

0

输入输出样例 #3

输入 #3

6 20
8 12
14 20
11 13
5 19
4 11
1 6

输出 #3

102

说明/提示

约定

  • 1N,M2×1051\le N,M\le 2\times 10^5
  • 1LiRiM1\le L_i\le R_i\le M
  • 所有输入均为整数

(l,r)=(1,1),(2,2),(2,3),(3,3),(4,4)(l,r)=(1,1),(2,2),(2,3),(3,3),(4,4)55 个都满足条件。

例如 (l,r)=(1,3)(l,r)=(1,3) 不满足条件。这是因为区间 [1,3][1,3] 完全包含了区间 [1,2][1,2]

此时不存在满足条件的整数对。

Translation by

/user/1332013
ng](/user/1332013)。

1128(B)

Not Attended
Status
Done
Rule
ACM/ICPC
Problem
5
Start at
2025-11-28 14:00
End at
2025-11-28 16:30
Duration
2.5 hour(s)
Host
Partic.
70