CF1389F.Bicolored Segments

普及/提高-

通过率:0%

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:

  • titjt_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.

输入格式

The first line contains a single integer nn ( 1n21051 \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 ( 1liri109;ti{1,2}1 \le l_i \le r_i \le 10^9; t_i \in \{1, 2\} ) — description of the ii -th segment.

输出格式

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
首页