#P6372. Overlapping Cuboids Pairs
Overlapping Cuboids Pairs
Overlapping Cuboids Pairs
Given n cuboids in three-dimensional space, each defined by two opposite vertices, count the number of pairs of cuboids that overlap (i.e. have any common points, including contacting at a single point).
Two cuboids with coordinate intervals \([x_{low}, x_{high}], [y_{low}, y_{high}], [z_{low}, z_{high}]\) and \([x'_{low}, x'_{high}], [y'_{low}, y'_{high}], [z'_{low}, z'_{high}]\) are considered to overlap if and only if they satisfy:
[ \max(x_{low}, x'{low}) \leq \min(x{high}, x'{high}),] [ \max(y{low}, y'{low}) \leq \min(y{high}, y'{high}),] [ \max(z{low}, z'{low}) \leq \min(z{high}, z'_{high}).]
If a pair touches only at a point (or along an edge/face), it is still counted as overlapping.
inputFormat
The first line contains an integer n (1 ≤ n ≤ 104) representing the number of cuboids.
Each of the next n lines contains six integers: x1 y1 z1 x2 y2 z2
, representing the coordinates of two opposite vertices of a cuboid. The coordinates can be given in any order; you should determine the lower and upper bounds for each dimension.
outputFormat
Output a single integer representing the number of pairs of cuboids that overlap.
sample
2
0 0 0 1 1 1
1 1 1 2 2 2
1