I was trying to solve 2024 Argentinian Programming Tournament (TAP) problem H (https://mirror.codeforces.com/gym/105321) and got stuck on a subproblem, but the contest doesn't have an editorial.
I have N axis-aligned rectangles that don't intersect each other (not even at corners), but some can be nested inside others. I need to efficiently find the "parent" of each rectangle, meaning the smallest rectangle that completely contains it. The trivial approach would be O(N^2): for each rectangle, check all others to see which contain it, but this would be too slow. I was thinking about sweep line algorithms but I can't figure it out.
Is there a standard algorithm for this problem?







