CDQ divide and conquer Created 2026-10-20 Updated 2026-11-05
CDQ divide and conquer is an offline divide-and-conquer pattern that partitions items in one ordered dimension, solves each half recursively and counts or applies contributions from the left half to the right during a merge. For three-dimensional dominance counting, first order by one coordinate, then merge by a second while a Fenwick tree aggregates the third. The cross-half pass accounts for interactions not handled inside either recursive call. Tie conventions must match strict or non-strict comparisons, and temporary updates must be removed or isolated before unrelated subproblems. A common implementation takes time after coordinate compression.