Editorial for THICC '17 P3 - The God of Death


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: Kirito

This problem can be solved trivially with persistent data structures in \mathcal O(Q \log N).

Time Complexity: \mathcal O(Q \log N)

Alternatively, one can create an array for each target, representing each movement with <day, location>. Since the days are monotonically increasing, each query can be answered in \mathcal O(\log Q) with binary search.

Time Complexity: \mathcal O(Q \log Q)


Comments

There are no comments at the moment.