CF1389F.Bicolored Segments

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given nn segments [l1,r1],[l2,r2],…,[ln,rn][l_1, r_1], [l_2, r_2], \dots, [l_n, r_n]. Each segment has one of two colors: the ii-th segment's color is tit_i.

Let's call a pair of segments ii and jj bad if the following two conditions are met:

  • ti≠tjt_i \ne t_j;
  • the segments [li,ri][l_i, r_i] and [lj,rj][l_j, r_j] intersect, embed or touch, i. e. there exists an integer xx such that x∈[li,ri]x \in [l_i, r_i] and x∈[lj,rj]x \in [l_j, r_j].

Calculate the maximum number of segments that can be selected from the given ones, so that there is no bad pair among the selected ones.

给你 nn 条线段 [l1,r1],[l2,r2],…,[ln,rn][l_1, r_1], [l_2, r_2], \dots, [l_n, r_n]。每条线段具有两种颜色之一:第 ii 条线段的颜色为 tit_i。

若满足以下两个条件,则称一对线段 ii 和 jj 为坏对:

  • ti≠tjt_i \ne t_j;
  • 线段 [li,ri][l_i, r_i] 与 [lj,rj][l_j, r_j] 相交、嵌套或相接,即存在某个整数 xx,使得 x∈[li,ri]x \in [l_i, r_i] 且 x∈[lj,rj]x \in [l_j, r_j]。

请计算:从给定的线段中最多能选出多少条线段,使得其中不存在任何坏对。

输入格式

The first line contains a single integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — number of segments.

The next nn lines contains three integers li,ri,til_i, r_i, t_i (1≤li≤ri≤109;ti∈1,21 \le l_i \le r_i \le 10^9; t_i \in {1, 2}) — description of the ii-th segment.

第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)——线段的数量。

接下来的 nn 行每行包含三个整数 li,ri,til_i, r_i, t_i(1≤li≤ri≤1091 \le l_i \le r_i \le 10^9;ti∈{1,2}t_i \in \{1, 2\})——第 ii 条线段的描述。

输出格式

Print the maximum number of segments that can be selected, so that there is no bad pair among the selected segments.

输出可选择的线段的最大数量,使得所选线段中不存在坏对。

输入输出样例

  • 输入#1

    3
    1 3 1
    4 6 2
    2 5 1

    输出#1

    2
  • 输入#2

    5
    5 8 1
    1 3 2
    3 4 2
    6 6 1
    2 10 2

    输出#2

    4
  • 输入#3

    7
    19 20 1
    13 15 2
    6 11 2
    4 10 1
    14 17 1
    13 13 2
    5 9 1

    输出#3

    5

输入解题思路,AI测评打分。不知道怎么写?

首页