Editorial for DMPG '19 G1 - Camera Calibration Challenge


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.

Authors: Kirito, AvaLovelace

This problem was greatly inspired by this DMOPC problem. The first subtask can be solved in the same manner as it.

For the remaining 90% of points, we can take advantage of some monotonic properties. Observe that as εi increases, the number of elements that become "clipped" monotonically increases.

Thus, we can push the elements in the grid into a queue in descending bi,j. We maintain the current sum sn of non-clipped elements and the number sc of clipped elements. For each query i, we want to find the first Ci such that Cisn+1.0scNMεi. Rearranging, we find that CiNMεi1.0scsn. Let's call NMεi1.0sc our target sum, t.

We then process the queries in ascending εi. For each query i, we know that Ci must be at least tsn106. However, setting Ci to this value may result in some of the values clipping and the true Ci being larger. Thus, as long as the elements at the front of the queue are clipped by our current Ci, we will pop them off and recalculate sn, sc, and Ci. Once we have found a Ci that does not clip any additional elements, we have our answer. As each of the NM elements is popped at most once, the overall complexity of this stage is O(NM+Q).

However, there is one thing to watch out for. There are certain values for t, sc, and the element at the front of the queue bfront such that when Cnew=t1.0snbfront106 is calculated, it is smaller than the previous Cpre=tsn106. (One such set of values from the test data is t=25105059110, sc=22570341993, and bfront=899035.) How is this possible if C is supposed to be monotonically increasing?

The problem lies with the ceiling function. In such cases, Cpre=tsn106 does not cause bfront to clip, but Cpre=tsn106 does. This causes us to pop bfront off the queue and calculate Cnew, which in these cases turns out to be less than Cpre. However, since we needed C to be at least Cpre in order to clip bfront, the correct answer would be Cpre, not Cnew! These cases are a common source of WA's but are easily dealt with by updating Ccur to max(Cpre,Cnew) rather than replacing it with Cnew.

Time Complexity: O(NMlog(NM)+QlogQ)


Comments

There are no comments at the moment.