Editorial for DMOPC '17 Contest 5 P2 - Mimi and Binary


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

For the first subtask, it suffices to iterate through the suffix [x_i, \dots] and return the first index where there are y_i occurrences of z_i.

Time Complexity: \mathcal O(NQ)

For the second subtask, we can preprocess the array by keeping 2 dynamic arrays, one for zeroes and one for ones, as a second array which holds the index of the i^\text{th} index in each of these dynamic arrays. A query can thus be answered in \mathcal O(1) time by retrieving the index of the left endpoint from the array, and adding y_i, and then finding this index in the dynamic array.

Time Complexity: \mathcal O(N+Q)


Comments

There are no comments at the moment.