[SDOI2005] 区间

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Problem Description

Given nn closed intervals [ai,bi][a_i, b_i] (1in1 \le i \le n). The union of these intervals can be represented as a union of pairwise disjoint closed intervals. Your task is to find, among all such representations, the one that contains the fewest intervals. Your output should be in ascending order. If two intervals [a,b][a, b] and [c,d][c, d] are in ascending order, then we have ab<cda \le b < c \le d.

Please write a program to:

  • read these intervals;
  • compute the pairwise disjoint closed intervals that satisfy the given condition;
  • output these intervals in ascending order.

Input Format

The first line contains an integer nn (3n500003 \le n \le 50000), the number of intervals.
Each of the following nn lines describes an interval. The ii-th line contains two integers ai,bia_i, b_i (1aibi10000001 \le a _ i \leq b _ i \le 1000000), representing the interval [ai,bi][a_i, b_i].

Output Format

Output the computed pairwise disjoint intervals. Each line describes one interval and contains two integers separated by a space, which are the lower and upper bounds of the interval. You should sort the intervals in ascending order.

5
5 6
1 4
10 10
6 9
8 10

1 4
5 10

Hint

For 100%100 \% of the testdata, 3n500003 \le n \le 50000, 1aibi10000001 \le a _ i \leq b _ i \le 1000000.

Translated by ChatGPT 5

第 25 课:贪心算法

未认领
状态
已结束
题目
21
开始时间
2026-7-7 19:00
截止时间
2026-7-14 19:00
可延期
24 小时