Jekyll2021-07-20T17:57:59+00:00https://mosesxu.ca/feed.xmlMoses’ WebsiteMy Personal WebsiteMoses Xumoses@mosesxu.netLazy Divide and Conquer2021-07-14T22:31:14+00:002021-07-14T22:31:14+00:00https://mosesxu.ca/contest/lazy-cdq<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: { equationNumbers: { autoNumber: "AMS" } }
});
</script>
<script type="text/javascript" async="" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<p>Unfortunately, this blog is still heavily work in progress, so I’ll just give a gist of the idea, what it was inspired from,
and some of its pitfalls (or rather, its one major drawback).</p>
<p>This trick allows us to solve problems with 2D range updates and queries offline with only one log factor above its 1D equivalent.
Thus, it is quite niche but can be very useful in certain sitautions.</p>
<p>Lazy D&C is inspired from the ‘segment tree over time’ (often introduced as an offline solution to
dynamic connectivity with DSU) and ‘lazy segment tree without propagation’ tricks. Here, we run D&C similar to a
segment tree but offline across one of the dimensions (similar to the ‘time’ dimension in the ‘segment tree over time’ trick).</p>
<p>When we encounter a query that covers a whole range in our D&C, we apply all updates that are within (or cover) that range to it.
Similarly, when we hit an update that covers a whole range, we apply it to all queries that are within (or cover) that range.
Otherwise, we break them into halves at the midpoint of the current range and
push them to the next layer of the D&C.</p>
<p>Some of this may feel confusing and out of place, but reading up on the offline D&C solution to APIO ‘19 P3 (Street Lamps) may be
helpful in conceptualizing what the idea is.</p>
<p>If you are also in need of some code here is a <a href="https://mosesxu.ca/dmojsols/view/coci18c2p5/cpp">problem (and solution)</a> that uses this technique if you
are curious.</p>
<p>Lastly, the biggest pitfall of the technique is that it requires you to apply and undo updates/queries multiple times, which gives it
quite a large constant factor.</p>Moses Xumoses@mosesxu.net