#P9561. [SDCPC2023] Colorful Segments

[SDCPC2023] Colorful Segments

题目描述

Consider nn segments on the number axis, where the left endpoint of the ii-th segment is lil_i and the right endpoint is rir_i. Each segment has a color where the color of the ii-th segment is cic_i (0ci10 \le c_i \le 1). There are two types of colors, where ci=0c_i = 0 indicates a red segment and ci=1c_i = 1 indicates a blue segment.

You need to choose some segments (you can also choose no segments at all). If any two chosen segments overlap, then they must have the same color.

Calculate the number of ways to choose segments.

We say segment ii overlaps with segment jj, if there exists a real number xx satisfying both lixril_i \le x \le r_i and ljxrjl_j \le x \le r_j.

We say two ways of choosing segments are different, if there exists an integer 1kn1 \le k \le n such that the kk-th segment is chosen in one of the ways and is not chosen in the other.

输入格式

There are multiple test cases. The first line of the input contains an integer TT indicating the number of test cases. For each test case:

The first line contains an integer nn (1n1051 \le n \le 10^5) indicating the number of segments.

For the following nn lines, the ii-th line contains three integers lil_i, rir_i and cic_i (1liri1091 \le l_i \le r_i \le 10^9, 0ci10 \le c_i \le 1) indicating the left and right endpoints and the color of the ii-th segment.

It's guaranteed that the sum of nn of all test cases will not exceed 5×1055 \times 10^5.

输出格式

For each test case output one line containing one integer indicating the number of ways to choose segments. As the answer may be large, please output the answer modulo 998244353998244353.

题目大意

【题目描述】

考虑数轴上的 nn 条线段,其中第 ii 条线段的左端点为 lil_i,右端点为 rir_i。每一条线段都被涂上了颜色,其中第 ii 条线段的颜色为 cic_i0ci10 \le c_i \le 1)。颜色共有两种,ci=0c_i = 0 代表一条红色的线段,而 ci=1c_i = 1 代表一条蓝色的线段。

您需要选择若干条线段(可以不选择任何线段)。如果您选择的任意两条线段有重合,则这两条线段的颜色必须相同。

求选择线段的不同方案数。

称第 ii 条线段和第 jj 条线段有重合,若存在一个实数 xx 同时满足 lixril_i \le x \le r_iljxrjl_j \le x \le r_j

称两种选择线段的方案是不同的,若存在一个整数 1kn1 \le k \le n,满足第 kk 条线段在其中一个方案中被选择,而在另一个方案中没有被选择。

【输入格式】

有多组测试数据。第一行输入一个整数 TT 表示测试数据组数。对于每组测试数据:

第一行输入一个整数 nn1n1051 \le n \le 10^5)表示线段的数量。

对于接下来 nn 行,第 ii 行输入三个整数 lil_irir_icic_i1liri1091 \le l_i \le r_i \le 10^90ci10 \le c_i \le 1)表示第 ii 条线段的左右端点以及颜色。

保证所有数据 nn 之和不超过 5×1055 \times 10^5

【输出格式】

每组数据输出一行一个整数表示选择线段的不同方案数。由于答案可能很大,请将答案对 998244353998244353 取模后输出。

【样例解释】

对于第一组样例数据,您不能同时选择第 11 和第 22 条线段,也不能同时选择第 22 和第 33 条线段,因为它们有重合且颜色不同。

对于第二组样例数据,因为第 22 条线段与第 11 和第 33 条线段都不重合,因此您可以任意选择线段。

2
3
1 5 0
3 6 1
4 7 0
3
1 5 0
7 9 1
3 6 0
5
8

提示

For the first sample test case, you cannot choose the 11-st and the 22-nd segment, or the 22-nd and the 33-rd segment at the same time, because they overlap with each other and have different colors.

For the second sample test case, as the 22-nd segment does not overlap with the 11-st and the 33-rd segment, you can choose them arbitrary.