靠着手速和没有 FST 上了大分,很开心(
场上没时间做 I,还看错题了。感觉再给我 30min 就可以过了。
把 (a) 序列进行划分,每一段内的 (a) 值都相等且这个 (a) 值等于段的长度。一个序列最多存在一个划分。设这个划分的长度为 (f_1,f_2,f_3,...,f_m)。
划分内要求是一个上升/下降段。而划分外部要求相邻两个不能组成一个连续段。
自然想到容斥。钦定一些相邻段能组成连续段,就把 (f) 划分成几个上升/下降段。设这个划分的长度为 (k),那么方案数即为 (k! 2^{ ext{长度不为 1 的段个数}}),容斥系数为 ((-1)^{m-k})。
分治 (
m FFT) 即可(对于一个分治中心 维护 l 和 l-1 是否被钦定
和 r 和 r+1 是否被钦定
的关于段数的多项式)
实际实现中,把 "长度和不为 1 的段个数" 转化成了 (k) 减去 "长度和为 1 的段的个数",长度和为 1 的段只有可能是长度为 1 的连续段,很好处理。