你可以浏览这个题解的中文版本。
The images are hosted on Github, use an accelerator if it fails to load.
It is first easy to think of duplicating the sequence over and over again, breaking the ring into a chain, with each query i.e. querying a sub-segment answer.
Let be transferable from or , and consider a greedy.
where denotes the points from which can be transferred, i.e. .
Since holds, we do not need to consider the contribution of the interval . Instead, , i.e., all points that can be transferred to can be transferred to , so it is sufficient to choose a transfer from . That is, it is not inferior to transfer from the smaller of . Maintained in ST tables, complexity .
You submited the code and found it accepted in the simulation game. You can use multiplicative preprocessing to figure out where you can jump steps, optimising to .
