Box Art
Time limit1sMemory limit128 MB
Given a bounding box and up to 2000 axis-aligned boxes, compute the volume of their union clipped to the bounding box.
- Level
Hard8 of 10
- Topics
- Geometry, Sorting, Segment tree, Prefix sum
- Solved
- No attempts yet
Problem
The world-famous artist A.A. Blox, celebrated for his cubic sculptures, has invented a brand-new way to create striking artwork from a rectangular block of transparent acrylic glass. Using the patented laser device built by his friend T.D. Resal, he can change the colour of parts of the originally colourless block. Because the laser device is still a prototype, he can only colour a rectangular region whose faces are parallel to the faces of the large block ("axis aligned").
The value of the finished piece is the volume of coloured acrylic glass. Since A.A. Blox is not fond of mathematics, he has hired you to compute the price of his artwork.

Given an axis-aligned initial box and a set of axis-aligned boxes, compute the volume of the union of all parts of the boxes in that lie inside . Volume covered by several boxes must be counted only once.
Input
The first line contains the number of scenarios.
Each scenario begins with a line x1 y1 z1 x2 y2 z2 giving the two opposite corners and of the initial box . The numbers are separated by single spaces.
The next line contains the number () of boxes in that were coloured by the laser device, followed by lines, each containing x1 y1 z1 x2 y2 z2 for the two opposite corners of one box in .
All coordinates are integers in the range to , and every line satisfies , , and .
Output
For every scenario, first print a line Scenario #i:, where is the scenario number starting at . Then print a line with the total volume of coloured acrylic glass. Separate consecutive scenarios with a blank line.