Observation: For a particular magic number mjm_j , among two participant with same XiX_i and LimjRiL_i \leq m_j \leq R_i for both of them, the participant with higher LiL_i will reach there first. If LiL_i if same for both of them, the one with lower index will reach there first.

As LiL_i is divisible by XiX_i we can iterate for all distinct values that can be XiX_ijust once. When we iterate for a specific XX, let’s consider a specific point pp within the iteration. We will consider the latest participant i.e the participant with maximum LiL_i till now. If there is two or more participants with maximum LiL_i we will prioritize the one with lower index. And, we will eleminate the ones with lesser RiR_i than pp. This can be done using a stack. Then we will update the result by counting the number of minimum rounds are needed to reach pp by the participants with this XX. We can precalculate it for all possible distinct XX for all possible magic numbers.

As all the iteration will be done for just once for a distinct number the complexity will be, O(nlog(n))O(nlog(n)).

Statistics

50% Solution Ratio
serotoninEarliest, Dec '21
serotoninFastest, 0.5s
nusuBotLightest, 177 MB
serotoninShortest, 1016B
Toph uses cookies. By continuing you agree to our Cookie Policy.