#2630. 区间的并

区间的并

Description

给定一个数轴上的 <math xmlns="http://www.w3.org/1998/Math/MathML">n 个闭区间,第 <math xmlns="http://www.w3.org/1998/Math/MathML">i 个闭区间的两端点为<math xmlns="http://www.w3.org/1998/Math/MathML">[ai,bi],它们的并集可以表示为若干不相交的闭区间,请按照左端点从小到大的顺序输出这些区间的并集。

Input Format

  • 第一行:单个整数 <math xmlns="http://www.w3.org/1998/Math/MathML">n
  • 第二行到第 <math xmlns="http://www.w3.org/1998/Math/MathML">n+1 行:每行两个整数 <math xmlns="http://www.w3.org/1998/Math/MathML">ai 与 <math xmlns="http://www.w3.org/1998/Math/MathML">bi 表示一个闭区间 <math xmlns="http://www.w3.org/1998/Math/MathML">[ai,bi]

Output Format

若干行:表示输入区间的并集。每行两个整数,表示一个闭区间的两个端点,这些闭区间应该按照起点从小到大排序。
3
10 12
1 3
2 5
1 5
10 12

Hint

  • 对于 <math xmlns="http://www.w3.org/1998/Math/MathML">50% 的数据,<math xmlns="http://www.w3.org/1998/Math/MathML">1n104<math xmlns="http://www.w3.org/1998/Math/MathML">0aibi104
  • 对于 <math xmlns="http://www.w3.org/1998/Math/MathML">100% 的数据,<math xmlns="http://www.w3.org/1998/Math/MathML">1n105<math xmlns="http://www.w3.org/1998/Math/MathML">0aibi109

Source

贪心 上海市2023年2月赛