CF1389F.Bicolored Segments
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given n segments [l1,r1],[l2,r2],…,[ln,rn]. Each segment has one of two colors: the i-th segment's color is ti.
Let's call a pair of segments i and j bad if the following two conditions are met:
- ti=tj;
- the segments [li,ri] and [lj,rj] intersect, embed or touch, i. e. there exists an integer x such that x∈[li,ri] and x∈[lj,rj].
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.
给你 n 条线段 [l1,r1],[l2,r2],…,[ln,rn]。每条线段具有两种颜色之一:第 i 条线段的颜色为 ti。
若满足以下两个条件,则称一对线段 i 和 j 为坏对:
- ti=tj;
- 线段 [li,ri] 与 [lj,rj] 相交、嵌套或相接,即存在某个整数 x,使得 x∈[li,ri] 且 x∈[lj,rj]。
请计算:从给定的线段中最多能选出多少条线段,使得其中不存在任何坏对。
输入格式
The first line contains a single integer n (1≤n≤2⋅105) — number of segments.
The next n lines contains three integers li,ri,ti (1≤li≤ri≤109;ti∈1,2) — description of the i-th segment.
第一行包含一个整数 n(1≤n≤2⋅105)——线段的数量。
接下来的 n 行每行包含三个整数 li,ri,ti(1≤li≤ri≤109;ti∈{1,2})——第 i 条线段的描述。
输出格式
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测评打分。不知道怎么写?