Sculpture
Time limit1sMemory limit128 MB
Given a set of axis-aligned boxes in 3D, compute the total exposed surface area and total volume, including internal cavities not reachable by liquid, using 3D space decomposition.
- Level
Hard8 of 10
- Topics
- Geometry, Matrix, Simulation
- Solved
- No attempts yet
Problem
Imagine a box made of copper plate. Imagine a second one intersecting the first, and several others intersecting one another (or not). That is how a sculptor builds his sculptures. In fact he does not build them himself; he only makes the design, and the actual construction is contracted out to a construction company.
To calculate the construction cost, the company needs the total area of copper plate involved. Parts of a box that are hidden inside another box are, of course, not made of copper (copper is expensive, and prices keep rising).
After construction, the whole piece is plunged into a bath of chemicals. To keep the bath from overflowing, the company also needs the total volume of the construction.
Given a construction that is a collection of boxes, compute its total copper-plate area and its total volume.
Some designs are connected and some are not; either way, we want the total area and the total volume. The boxes may completely enclose a region of space that belongs to none of them. Because the liquid cannot reach that region, its volume must be added to the total volume. Copper plate bordering such an enclosed region is superfluous, so it does not add to the area.
Input
The first line contains a single positive integer: the number of test cases, at most . Each test case is given as follows:
- One line with an integer (): the number of boxes.
- lines, each with six positive integers (). The point is the corner of the box with the smallest coordinates, and are its side lengths along the respective axes. All lengths are in centimeters, and every box has edges parallel to the coordinate axes.
Output
For each test case, print one line with two integers separated by a single space: the total amount of copper plate needed (in square centimeters) and the total volume (in cubic centimeters).