首页 > 其他分享 >[SDCPC2023] Colorful Segments 线段树转移DP

[SDCPC2023] Colorful Segments 线段树转移DP

时间:2024-05-28 12:22:33浏览次数:14  
标签:le 颜色 Colorful 线段 SDCPC2023 segments test segment Segments

Codeforces 链接​

  洛谷题目链接

# [SDCPC2023] Colorful Segments

## 题面翻译

**【题目描述】**

考虑数轴上的 $n$ 条线段,其中第 $i$ 条线段的左端点为 $l_i$,右端点为 $r_i$。每一条线段都被涂上了颜色,其中第 $i$ 条线段的颜色为 $c_i$($0 \le c_i \le 1$)。颜色共有两种,$c_i = 0$ 代表一条红色的线段,而 $c_i = 1$ 代表一条蓝色的线段。

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

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

称第 $i$ 条线段和第 $j$ 条线段有重合,若存在一个实数 $x$ 同时满足 $l_i \le x \le r_i$ 且 $l_j \le x \le r_j$。

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

**【输入格式】**

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

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

对于接下来 $n$ 行,第 $i$ 行输入三个整数 $l_i$,$r_i$ 和 $c_i$($1 \le l_i \le r_i \le 10^9$,$0 \le c_i \le 1$)表示第 $i$ 条线段的左右端点以及颜色。

保证所有数据 $n$ 之和不超过 $5 \times 10^5$。

**【输出格式】**

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

**【样例解释】**

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

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

## 题目描述

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 $i$ overlaps with segment $j$, if there exists a real number $x$ satisfying both $l_i \le x \le r_i$ and $l_j \le x \le r_j$.

We say two ways of choosing segments are different, if there exists an integer $1 \le k \le n$ such that the $k$-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 $n$ ($1 \le n \le 10^5$) indicating the number of segments.

For the following $n$ lines, the $i$-th line contains three integers $l_i$, $r_i$ and $c_i$ ($1 \le l_i \le r_i \le 10^9$, $0 \le c_i \le 1$) indicating the left and right endpoints and the color of the $i$-th segment.

It's guaranteed that the sum of $n$ of all test cases will not exceed $5 \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$.

## 样例 #1

### 样例输入 #1

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

### 样例输出 #1

```
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 $2$-nd segment does not overlap with the $1$-st and the $3$-rd segment, you can choose them arbitrary.

 


按线段的 r 端点排序 对两种颜色建两颗不同的线段树 ,枚举当前线段,设当前线段颜色是 A, 当前线段如果不选的话, 当前线段的 l 左边的颜色B的线段全部都能转移到当前的 r 端点处 ,当前答案转移到颜色为A的线段树, 如果选择选当前的线段的话 ,当前线段的l  左边的颜色B的线段全部 * 2, 因为颜色B可以选或者不选,当前答案转移到颜色为B的线段树

最后答案即为某一种颜色全部加起来,注意最开始从0开始往右边转移

 

标签:le,颜色,Colorful,线段,SDCPC2023,segments,test,segment,Segments
From: https://www.cnblogs.com/Sakuyamaid/p/18217664

相关文章

  • Topcoder SRM616-Div1-Lv2 ColorfulCoins
    涉及知识点:奇妙Ad-hoc前言一道很不常规的题目,思维难度大代码简单,而且这种思路很难在赛时想到,故记录一下。题意某国的货币系统硬币有\(n\(\leq60)\)种面额\(val_i\(\leq10^{18})\),其中最小的面额为\(1\),并且所有的面额之间都保证两两有倍数关系,每种面额的硬币有独一无......
  • F. Equal XOR Segments
    原题链接题解1.如果能分成偶数个区间,那么一定能分为两个区间2.如果能分为奇数个区间,那么一定能分为三个区间3.能分为两个区间,说明区间异或和为\(0\)4.能分为三个区间,这三个区间分别为区间\(a,b,c\),则\(ab\)区间异或和为零,\(bc\)区间异或和为零code#include<bits/std......
  • Jumping Through Segments
    题目:链接:https://www.luogu.com.cn/problem/CF1907D大致思路:二分模拟关键点:①确定二分区间:最小值为第一次跳的左边界,最大值为连续两个线段的最远值(注意,应该有四种情况:左1减右1,左2减右1,左1减右2,左2减右2,取绝对值);②确定如何模拟:递推:假定跳跃长度≤k(mid),那么下一个最远就是ra+......
  • [ARC176F] Colorful Star
    MyBlogs[ARC176F]ColorfulStar感觉很考验想象力和计数基本功QWQ。首先考虑给定了局面之后如何进行判定。考虑把覆盖的过程倒着做:如果\(i\)旁边有和它颜色相同的棋子,那它就可以变成任意的颜色,然后要求最终能不能\(n\)种颜色都只剩一种。然后这个还是不太本质。考虑如果......
  • [ABC314Ex] Disk and Segments题解(退火实现)
    一到比较水的退火题(虽然也调了3h)题意在平面直角坐标系中,有\(n\)条线段,第\(i\)条的端点是\((a_i,b_i)\)和$(c_i,d_i)$,任意线段不共点。(这里笔者为了方便会默认\(a_i<c_i\))你要在平面上画一个圆,使得任意一条线段都和圆周或圆内部有至少一个公共点,求满足条件的圆的最小......
  • P9562 [SDCPC2023] G-Matching 题解
    题目描述给定长度为\(n\)的整数序列\(a_1,a_2,\cdots,a_n\),我们将从该序列中构造出一张无向图\(G\)。具体来说,对于所有\(1\lei<j\len\),若\(i-j=a_i-a_j\),则\(G\)中将存在一条连接节点\(i\)与\(j\)的无向边,其边权为\((a_i+a_j)\)。求\(G\)的一个......
  • 「ABC215G」 Colorful Candies 2
    题意概括有\(n\)个糖果,每种都有一个颜色\(c_i\),求对于所有\(k\in[1,n]\),求出\(C_n^k\)种方案中糖果种类的期望数,对\(998244353\)取模。分析通过期望的定义,设\(vis_i\)表示每种颜色有没有被选,颜色总数为\(m\),则期望为\(E(\sum\limits_{j=1}^{m}vis_j)\),由线性期望......
  • CF1196B Odd Sum Segments题解
    【问题分析】本题考了奇数。由此想到以下定律:奇数+偶数=奇数;奇数+奇数=偶数;偶数+偶数=偶数;所以偶数可以忽略不计,只有奇数可以对结果产生影响,所以我们只要注意奇数即可。经过思考可得奇数的个数至少为$k$个且比$k$多的个数为偶数,此时多出的奇数可组成偶数,对结果不产生......
  • CF1677E Tokitsukaze and Beautiful Subsegments
    (题目传送门)你就算再怎么套路我也做不出来……看到\(\maxa_k\),根据套路想到用单调栈处理出\(a_i\)左边第一个比它大的位置\(pre_i\),右边第一个比它大的位置\(nxt_i\)。枚举最大值\(a_i\)考虑它的贡献,显然若存在\(j,k\)满足\(nxt_i<j,k<pre_i\)且\(a_j\timesa_k=a......
  • An improved LSTM-based model for identifying high working intensity load segment
    一区topComputersandElectronicsinAgriculture题目:“基于改进lstm的拖拉机载荷谱高工作强度载荷段识别模型”(pdf)“AnimprovedLSTM-basedmodelforidentifyinghighworkingintensityloadsegmentsofthetractorloadspectrum”(pdf)分类问题针对的问题:......