注意到每个提示的第一行是不相交的,且第二行都在第二行左边。那么连上所有提示对应的边(即 $y_i\to h_i,y_i+1\to h_i+1,\ldots$)后形成的是内向树森林。两个位置能确定相同当且仅当在同一个连通块,我们只需要求出每个点所在的树根然后比对即可。求树根只需要把提示从后往前扫一遍,用取模加速同一个提示内跳的过程,求一次树根就是 $O(b)$ 的。总的复杂度为 $O((a+q)\cdot b)$。
QOJ.ac
QOJ
As we are currently experiencing an overwhelming number of web requests for fetching user submissions, we have temporarily disabled the full submissions list. You must now be logged in to view submissions.
Discussion #306 for Problem #3291. String Puzzle
Type: Editorial
Status: Open
Posted by: jiangly
Posted at: 2025-12-14 07:00:39
Last updated: 2025-12-14 07:00:41
题解
Comments
No comments yet.