#P9925. [POI 2023/2024 R1] Zapobiegliwy student

    ID: 11184 远端评测题 500ms 256MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>贪心POI(波兰)2023Special Judge构造

[POI 2023/2024 R1] Zapobiegliwy student

Background

Translated from XXXI Olimpiada Informatyczna - Stage 1 Zapobiegliwy student

Problem Description

Consider the following simple problem:

You have nn segments on the number line. You want to choose as many segments as possible so that they are pairwise disjoint.

I know you can do it, but you need to solve this:

You have nn segments on the number line. You want to choose as many pairs of segments (ui,vi)i=1k(u_i, v_i)_{i=1}^k as possible, i.e., maximize kk.

They must satisfy k+1k + 1 requirements:

  • u1,u2,,uku_1, u_2, \cdots, u_k are pairwise disjoint.
  • v1,u2,u3,,ukv_1, u_2, u_3, \cdots, u_k are pairwise disjoint.
  • u1,v2,u3,u4,,uku_1, v_2, u_3, u_4, \cdots, u_k are pairwise disjoint.
  • \cdots
  • u1,u2,,uk1,vku_1, u_2, \cdots, u_{k-1}, v_k are pairwise disjoint.

Here, for all ii, uiu_i and viv_i cannot be the same.

Input Format

The first line contains a positive integer n(n2)n (n \geq 2).

The next nn lines each contain two positive integers ai,bi(1ai<bi109)a_i, b_i (1 \leq a_i < b_i \leq 10^9), representing the two endpoints of a segment.

Two segments i,ji, j are disjoint if and only if biajb_i \leq a_j or bjaib_j \leq a_i.

Output Format

The first line contains a positive integer kk.

The next kk lines each contain two positive integers ui,viu_i, v_i, representing a pair of segment indices.

8
1 5
3 10
4 8
9 12
11 16
14 15
20 22
15 21

3
1 3
4 6
8 7

见附件
见附件
见附件
见附件

Hint

If your first line is correct but your construction is not (you may choose not to output a construction; in this case, do not output a newline), you can get 50%50\% of the score.

If your construction is valid and the first line differs from the answer by at most 11, you can get 15%15\% of the score.

Subtask ID Constraints Score
1 n3000n \leq 3000 40
2 n500000n \leq 500000 60

Translated by ChatGPT 5