Editorial for JDCC '15 Contest 3 P5 - Fireworks


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: aurpine

Method 1

This is a classic difference array problem. Increase the total brightness by B at A and decrease it by B at A + L.

Time Complexity: \mathcal{O}(N)
Space complexity: \mathcal{O}(N)


Method 2

Since there are a maximum of 10^7 seconds in a show but 10^4 fireworks, we don't need such a big array that will mainly be empty. We can use coordinate compression to speed up the program and to reduce memory usage. However, both methods pass. Use a map as the difference array.

Time Complexity: \mathcal{O}(M\log M)
Space complexity: \mathcal{O}(M)


Comments

There are no comments at the moment.