#P9561. [SDCPC 2023] Colorful Segments
[SDCPC 2023] Colorful Segments
题目描述
Consider segments on the number axis, where the left endpoint of the -th segment is and the right endpoint is . Each segment has a color where the color of the -th segment is (). There are two types of colors, where indicates a red segment and 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 overlaps with segment , if there exists a real number satisfying both and .
We say two ways of choosing segments are different, if there exists an integer such that the -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 indicating the number of test cases. For each test case:
The first line contains an integer () indicating the number of segments.
For the following lines, the -th line contains three integers , and (, ) indicating the left and right endpoints and the color of the -th segment.
It's guaranteed that the sum of of all test cases will not exceed .
输出格式
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 .
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 -st and the -nd segment, or the -nd and the -rd segment at the same time, because they overlap with each other and have different colors.
For the second sample test case, as the -nd segment does not overlap with the -st and the -rd segment, you can choose them arbitrary.
