Imagine you're a city planner managing a transportation network! You have n cities numbered from 0 to n-1, initially connected by a simple highway system where each city i has a direct road to city i+1.
Now comes the exciting part: you'll receive a series of road construction queries, where each query [u, v] represents building a new express highway from city u directly to city v. These new roads can create shortcuts that dramatically reduce travel time!
Your mission is to track how these new roads affect the shortest path from city 0 to city n-1 after each construction project. The key constraint is that the queries follow a specific pattern: no two queries will create overlapping or intersecting shortcuts.
Goal: Return an array where each element represents the shortest distance from city 0 to city n-1 after processing each query in sequence.
Input & Output
Constraints
- 3 โค n โค 105
- 1 โค queries.length โค 105
- queries[i].length == 2
- 0 โค queries[i][0] < queries[i][1] < n
- No two queries create intersecting shortcuts
- queries[i][0] โ 0 or queries[i][1] โ n - 1 for more than one query