#15769. [SDCPC 2023] Colorful Segments

    ID: 15769 传统题 4000ms 1024MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>P9561动态规划 DP线段树2023山东O2优化省赛/邀请赛

[SDCPC 2023] Colorful Segments

[SDCPC 2023] Colorful Segments

题目描述

Consider $n$ segments on the number axis, where the left endpoint of the $i$-th segment is $l_i$ and the right endpoint is $r_i$. Each segment has a color where the color of the $i$-th segment is $c_i$ ($0 \le c_i \le 1$). There are two types of colors, where $c_i = 0$ indicates a red segment and $c_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 li≤x≤ril_i \le x \le r_i and lj≤x≤rjl_j \le x \le r_j.

We say two ways of choosing segments are different, if there exists an integer 1≤k≤n1 \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 $T$ indicating the number of test cases. For each test case:

The first line contains an integer nn (1≤n≤1051 \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 (1≤li≤ri≤1091 \le l_i \le r_i \le 10^9, 0≤ci≤10 \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 $998244353$.
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 $1$-st and the $2$-nd segment, or the $2$-nd and the $3$-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. 标签: P9561|动态规划 DP|线段树|2023|山东|O2优化|省赛/邀请赛

来源

P9561|[SDCPC 2023] Colorful Segments