luogu#P9561. [SDCPC2023] Colorful Segments
[SDCPC2023] 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.