wx6110fa547fd20 2021-08-10 07:01:13 阅读数:455
Ideas
It's hard to imagine ! First of all, the choice of this question is not strategic , namely A,B The next step from anywhere is unique .
That is, we have to preprocess A,B The next location from each city , about A It's the second smallest value to the right , Yes B It is the minimum value to the right .
A good practice is to sort first , We record who is on the left and right of each number , Because they are candidates for the minimum , Then follow the subscript from left to right , For the current first , Obviously left or right exists , Just choose the small one , For this small value of the current position , If the minimum value is left , Just take the left and right of the left to take the smallest , Otherwise, take the left and right, and the right takes the smallest , After each calculation To delete this number , If the current position of l exist ,l The right side of the is marked as r, In the current position r Existential empathy . In this way, you can delete a number .
Then there is multiplication preprocessing , If you want to query, double the number of rounds , Finally, I made a special judgment A Can you take another step .
See code for details .
code
版权声明:本文为[wx6110fa547fd20]所创,转载请带上原文链接,感谢。 https://car.inotgo.com/2021/08/20210810065944672E.html