Editorial for ICPC PACNW 2016 J - Shopping


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.

First, this problem is equivalent to a cumulative mod over a range (that is, we take vmoda[l]moda[l+1]modmoda[r]). The second thing to notice is that if a[i]<v, then vmoda[i]v2 (to prove this, consider two cases: a[i]v2 and a[i]>v2).

This shows that any one shopper can buy at most log2v distinct items.

We can solve this by reducing it to the subproblem: given a range [i,j] and a number v, find the smallest index k where k<v, or report none exists. This can be solved with a range tree.

Alternatively, we can also solve this using a heap and processing items left to right.


Comments

There are no comments at the moment.