← 返回 scale.ai 的题目列表Party Time Blocks per Neighborhood (Intervals Aggregation & Free Time)
类型:online_judge
You are given party time intervals per neighborhood. Each interval is a closed interval [start, end] with start < end.
For each neighborhood, output:
The earliest start time among its intervals (min(start)) and the latest end time (max(end)).
After sorting that neighborhood’s intervals by start, find all gaps with no party within the overall range [earliest_start, latest_end] (i.e., the complement of the union of intervals inside that range). Output the gap intervals in ascending order.
Input (stdin)
First line: integer N, number of interval records.
Next N lines: neighborhood start end
neighborhood is a no-space string
start, end are integer timestamps
Output (stdout)
One line per neighborhood:
neighborhood earliest latest gaps
gaps formatted as [(s1,e1),(s2,e2),...], or [] if none.
Neighborhood order can be unspecified; recommended to output in lexicographic order.
Constraints
1 <= N <= 2*10^5
0 <= start < end <= 10^9
Total intervals across neighborhoods equals N
Target complexity: O(N log N).
Example
Input:
5
A 1 3
A 6 8
A 2 5
B 10 12
B 12 15
Output:
A 1 8 [(5,6)]
B 10 15 []
Example
Input
5
A 1 3
A 6 8
A 2 5
B 10 12
B 12 15
Output
A 1 8 [(5,6)]
B 10 15 []