CF1691E.Number of Groups

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given nn colored segments on the number line. Each segment is either colored red or blue. The ii -th segment can be represented by a tuple (ci,li,ri)(c_i, l_i, r_i) . The segment contains all the points in the range [li,ri][l_i, r_i] , inclusive, and its color denoted by cic_i :

  • if ci=0c_i = 0 , it is a red segment;
  • if ci=1c_i = 1 , it is a blue segment.

We say that two segments of different colors are connected, if they share at least one common point. Two segments belong to the same group, if they are either connected directly, or through a sequence of directly connected segments. Find the number of groups of segments.

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt ( 1t1051 \le t \le 10^5 ). Description of the test cases follows.

The first line of each test case contains a single integer nn ( 1n1051 \leq n \leq 10^5 ) — the number of segments.

Each of the next nn lines contains three integers ci,li,ric_i, l_i, r_i ( 0ci1,0liri1090 \leq c_i \leq 1, 0 \leq l_i \leq r_i \leq 10^9 ), describing the ii -th segment.

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5 .

输出格式

For each test case, print a single integer kk , the number of groups of segments.

输入输出样例

  • 输入#1

    2
    5
    0 0 5
    1 2 12
    0 4 7
    1 9 16
    0 13 19
    3
    1 0 1
    1 1 2
    0 3 4

    输出#1

    2
    3

说明/提示

In the first example there are 55 segments. The segments 11 and 22 are connected, because they are of different colors and share a point. Also, the segments 22 and 33 are connected, and so are segments 44 and 55 . Thus, there are two groups: one containing segments {1,2,3}\{1, 2, 3\} , and the other one containing segments {4,5}\{4, 5\} .

首页