Intervals - Count of Intervals Containing Each Point
The following code attempts to count intervals containing each point using line sweep. What subtle bug causes incorrect counts for points exactly at interval ends?
```python
def count_intervals_bug(intervals, points):
events = []
for start, end in intervals:
events.append((start, 1, -1))
events.append((end, -1, -1)) # Bug here: end instead of end+1
for i, p in enumerate(points):
events.append((p, 0, i))
events.sort(key=lambda x: (x[0], -x[1]))
active = 0
result = [0] * len(points)
for coord, typ, idx in events:
if typ == 1:
active += 1
elif typ == -1:
active -= 1
else:
result[idx] = active
return result
```
