猫树分治,静态 toptree 维护可用点和下界点 LCA 的 max\maxmax 用脚维护。O(nlog2n)\mathcal O(n\log^2n)O(nlog2n)。 不是我写的,洛谷和 QOJ 都过了,清华大学【】机子卡不过去,摆了。