#P9561. [SDCPC 2023] Colorful Segments

[SDCPC 2023] 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.

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.