#P2434. [SDOI2005] 区间

    ID: 1432 远端评测题 1000ms 125MiB 尝试: 1 已通过: 1 难度: 5 上传者: 标签>动态规划,dp贪心2005线段树各省省选山东广度优先搜索,BFS

[SDOI2005] 区间

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