Under construction

Still being built. Things may change

Safe Zone

Time limit9sMemory limit2048 MB

Summary
Given N axis-aligned rectangles, group them into alliances where rectangles connect through shared points, and report the groups.
Level

Medium7 of 10

Topics
Segment tree, Union-find, Sorting
Solved
No attempts yet

Problem

Due to a zombie virus, the Earth has been destroyed, and only NN military units survive. The Earth is a rectangular region in coordinate space that satisfies −109≤x≤109,−109≤y≤109-10^9 \leq x \leq 10^9, -10^9 \leq y \leq 10^9. Each military unit manages a rectangular safe zone. Specifically, for 0≤i≤N−10 \leq i \leq N - 1, the ii-th unit manages the interior and boundary of the rectangle A[i]≤x≤C[i],B[i]≤y≤D[i]A[i] \leq x \leq C[i], B[i] \leq y \leq D[i] as its safe zone.

Two military units are connected if there is a point contained in both of their safe zones. If ii and jj are connected, and jj and kk are connected, for distinct i,j,ki, j, k, then ii and kk are also connected. A set of military units is called an alliance if every unit in the set is connected to the others, and no unit in the set is connected to any unit outside the set.

Constraints

  • 1≤N≤500 0001 \le N \le 500\,000
  • −109≤A[i],B[i],C[i],D[i]≤109-10^{9} \le A[i], B[i], C[i], D[i] \le 10^{9} for all 0≤i≤N−10 \le i \le N-1
  • A[i]≤C[i]A[i] \leq C[i], B[i]≤D[i]B[i] \leq D[i]

Examples1

  1. Example 1

    Input
    1
    0 0 0 0
    
    Expected output
    1