For each query, consider all intervals that start <= query; among those that also end >= query, pick smallest length.
Sort intervals by start. Sort queries with original indices. Sweep queries increasing:
start <= q into a min-heap keyed by (length, end).end < q.At query time, heap contains exactly candidates that could cover current q, and min-heap ensures smallest length is chosen.
For each query, consider all intervals that start <= query; among those that also end >= query, pick smallest length.
Sort intervals by start. Sort queries with original indices. Sweep queries increasing:
start <= q into a min-heap keyed by (length, end).end < q.At query time, heap contains exactly candidates that could cover current q, and min-heap ensures smallest length is chosen.