Editorial for WC '18 Contest 4 S4 - Super Luigi Odyssey
Submitting an official solution before solving the problem yourself is a bannable offence.
Our approach will consist of two overall steps. In the first step, we'll only concern ourselves with determining which platform Luigi will arrive at after each event. In the second step, we'll then compute the actual amount of energy used along the way.
To handle the first step, we'll begin by sorting the platforms in increasing order of position, and then constructing a 2D segment tree of platform heights in time. This will allow us to efficiently simulate the sequence of events — for each type-2 or type-3 event , we can first determine the index of Luigi's current platform in the ordered list of non-submerged platforms (in other words, the number of platforms to the left of it whose heights exceed the lava's current height), and then find either the th or th non-submerged platform from the left (if any). Each of these may be queried using the segment tree in time. Over the course of this simulation, we'll assemble a list of jumping intervals , such that we know that Luigi will at some point jump platform-by-platform between platforms and while the lava height is .
In the second step, our task will be to compute the sum of these jumping intervals' energy costs. We'll perform a line sweep over lava heights in decreasing order, with an event for each jumping interval (at its given lava height), as well as an event for each platform (at its height, such that it will be non-submerged for all subsequent lava heights). Along the way, we'll maintain an ordered set of non-submerged platforms (represented as a Balanced Binary Search Tree), as well as a Fenwick Tree (also known as a Binary Indexed Tree) with the cost of jumping from each pillar to its next non-submerged pillar to the right (or if there's no such next pillar).
Each time a platform becomes unsubmerged, we can update the set in time, and then consider the neighbouring unsubmerged platforms to its left/right to also update the Fenwick Tree in time. Finally, each time we consider a jumping interval, we can query the Fenwick Tree for that interval of pillars in time to determine the sum of energy costs of the jumps within it. These energy cost sums should then all be added together to yield the final answer.
Overall, this gives us an algorithm with time complexity .
Comments