Ex - Enumerate Pairs Editorial
by
spheniscine
Additional Note
Note that the first official editorial (partition the plane to a grid of square packets with size \(K \times K\)) is the second half of Rabin’s closest pair algorithm. The first half is sampling of \(N\) randomly-picked pairs and finding their minimum distance \(K\). With high probability \(O(N)\) pairs should have distance \(< K\), and the rest proves that the algorithm completes in \(O(N)\) overall.
Note that even though we used distance \(< K\) instead of \(\le K\), this doesn’t affect the correctness of the proof in the official editorial, as we can replace the packet size with \(\alpha K\) for any constant \(\alpha \ge 1\) while only affecting the runtime by a constant factor. [It simply means we might need more subsquares of size \(\frac {K} {\sqrt 2}\) to tile the packet-neighborhood.] This also means that when dealing with integer points, we could optionally round \(K\) up to the nearest integer, to avoid having to accurately divide by an irrational square root during the “packeting” operation.
With this knowledge, you can try solving this problem on yosupo.jp.
posted:
last update:
