QOJ.ac

QOJ

Type: Editorial

Status: Open

Posted by: jiangly

Posted at: 2025-12-12 23:47:57

Last updated: 2025-12-12 23:48:01

Back to Problem

题解

每次变换就是在每个字符前面加上 $a$。我们倒过来考虑,要让 $f(s)$ 包含 $t$,那么首先 $t$ 中的 $b$ 不能同时出现在奇数位置和偶数位置。假设 $t$ 中的 $b$ 出现在奇数位置,那么令 $t$ 的奇数位置的子序列为 $t'$,那么 $f(s)$ 包含 $t$ 意味着 $s$ 包含 $t'$(如果 $t$ 的长度是偶数,还要求 $t'$ 后面有任意字符,也就是匹配位置不能在 $s$ 的末尾)。$b$ 出现在偶数位置和 $t$ 不包含 $b$ 的情况也类似。

每次过程都会让 $t$ 的长度减半,因此至多 $\log |t|$ 轮。时间复杂度 $O((|s|+|t|)\log |t|)$。

Comments

No comments yet.