[POI2005]A Journey to Mars --- Monotonous Queue

[POI2005]A Journey to Mars

Topic description:

Byteazar decides to go to Mars on a space station trip.

All the space stations on Mars are located on a circle. Byteazar landed on one of them and then began to travel in a circle.

Traveling requires fuel, one liter of fuel can only run 1 meter, and the fuel that can be supplied to each space station is different.

Every time Byteazar goes to a space station, he can take all the fuel of the space station. (His fuel tank has no capacity limit) But if at some point the fuel suddenly runs out, the trip will fail.

Byteazar needs to decide where to land so that he can return to where he landed after he has successfully visited all the space stations.

One detail is that after landing, he can choose to travel in either of two directions.

Number of space stations <= n

\(n <= 10^{6}\)

 

. . . . . . At first I suspected that I had misread the difficulty. . . . . .

The ring is first processed, and the ring can be broken into a chain after doubling the length.

Conditions for being able to go anywhere: the amount of fuel in any place on the way > the amount of distance traveled

Therefore, maintain a monotonic queue with a length of \(n\), and maintain the minimum value of the amount of oil - the amount of travel. If it is < 0, it will not work, otherwise it can be

Note that walking in a circle is not necessarily clockwise, but counterclockwise.

So flip the sequence and do it again.

 

code here

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324837591&siteId=291194637