Editorial for WC '18 Contest 1 S4 - Bad Influence


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.

Let Vi be the volatility of students 1i. The volatility of a set of students is simply the number of students i who cannot be coerced into using their phones by anybody else (in other words, the number of students i for which there exists no student j such Si<Sj and DjRjDiDj+Rj). We can thus think of each student as contributing either 0 or 1 volatility to each V value. Let Mi be the smallest value of j which satisfies the above conditions (or Mi=N+1 if there's no such j). If Mii, then student i contributes no volatility at all, and otherwise, they contribute 1 volatility to each of the values Vi(Mi1). So, if we had the values M1N, we could use them to compute the volatilities V1N with a simple O(N) sweep.

What remains is computing the values M1N efficiently. Let's process the N students in decreasing order of S value, either by explicitly sorting them by their S values, or by keying them by their S values and then iterating over all possible S values from 106 down to 1. Let Xd be the minimum index (in the original ordered student list) of any student processed so far whose range of influence includes desk d (or Xd= if there's been no such student so far). When processing student i, we can observe that Mi must be equal to XPi. And upon finishing with student i, we should update Xd to min(Xd,i) for each desk d in the inclusive interval [DiRi,Di+Ri].

Let's maintain the values X1K (where K is the maximum possible D value) using a segment tree with lazy propagation, in which each node stores the minimum value of any X value in its interval, as well as the minimum new value which all X values in its interval should lazily be updated with. This allows us to both query an X value and update a range of X values as necessary in O(logK) time each, resulting in an overall time complexity of O((NlogK)+Z) (where K is the maximum possible D value and Z is the maximum possible S value).


Comments

There are no comments at the moment.