版本比较
题解[P7361拜神]
正文
增加 1 行删除 1 行
4 行未改动56789910111213127 行未改动全部展开4 行未改动思路还较清新,先将询问按右端点 $r$ 排序,看对每个询问 $l$ 能怎么方便求出。
将每个 $[1,r]$ 内的子串 $p$ ,其在 $[1,r]$ 中**次后出现的位置**的右端点与左端点看做一条线段 $[s_p,t_p]$。
那对每个 $l$ 只需查出 $\mathrm{Max}\left\{\left(\mathop{\mathrm{Max}}\limits_{s_p\leq l\leq t_p}t_p-l+1\right),\left(\mathop{\mathrm{Max}}\limits_{s_p\geq l}\ t_p-s_p+1\right)\right\}$ 那对每个 $l$ 只需查出 $\mathrm{Max}\left\{\left(\mathop{\mathrm{Max}}\limits_{s_p\leq l\leq t_p}t_p-l+1\right),\left(\mathop{\mathrm{Max}}\limits_{s_p\geq l}\ t_p-s_p+1\right)\right\}$
这相当于是找出覆盖 $l$ 的线段中的**右端点最大值** $-l$ ,与及不覆盖 $l$ 且在 $l$ 右侧的**线段长度**最大值的最大值。
由于对于 $\text{endpos}$ 相同的子串右端点集合相同,且上式需要的线段是越长越好。127 行未改动全部展开