optimize rectangles merge without DisjointSet grouping