Real-Time Navigation
Time limit2.5sMemory limit512 MB
Given two expressways joined by N bridges, answer shortest travel time queries while road and bridge times change.
- Level
Medium7 of 10
- Topics
- Segment tree, Graph, Shortest path, Dynamic programming
- Solved
- No attempts yet
Problem
Dijkstra's algorithm made it easy to find routes. However, drivers kept using the same few roads, so traffic jams got worse. The Korean Expressway Corporation then edited the travel time data for some roads so that the navigation system would recommend other routes. Soon, other roads started to jam.
As new roads kept getting congested, the Korean Expressway Corporation changed the road data more and more often. However, Dijkstra's algorithm performs operations every time the road data changes, and the navigation server went down.
After this serious problem, the navigation company began writing new software that quickly finds the shortest path whenever road data changes. First, the company will model only the Gangbyeon Expressway and the Olympic Expressway sections, which have the highest demand, and find shortest paths there.
The Gangbyeon Expressway runs on the north side of the Han River, and the Olympic Expressway runs on the south side. Each road has junctions. The junctions on the Gangbyeon Expressway are coded N-1, N-2, ..., N-N from the westernmost one in order. The junctions on the Olympic Expressway are coded S-1, S-2, ..., S-N from the westernmost one in order. Road on the Gangbyeon Expressway connects junctions N-i and N-(i+1). Road on the Olympic Expressway connects junctions S-i and S-(i+1). Bridge across the Han River connects junctions N-i and S-i. Each road and bridge takes a fixed amount of time to cross.
The navigation server initially has the travel time data for roads. After that, it receives messages from the Korean Expressway Corporation saying that the travel time of a specific road has changed. Whenever a driver asks for the fastest way from one place to another, the server must quickly compute the answer and send it back. Write a program that handles these two kinds of queries quickly. Note that a route that crosses the bridges several times can also be an answer.
Input
The first line contains the number of bridges . ()
The second line contains the travel times for the roads on the Gangbyeon Expressway, in order from the west. ()
The third line contains the travel times for the roads on the Olympic Expressway, in order from the west. ()
The fourth line contains the travel times for the bridges across the Han River, in order from the west. ()
The fifth line contains the number of queries . ()
The next lines each contain one query in one of the following formats.
1 a b: Find the minimum time needed to go from junction to junction . and are different. Junction on the Gangbyeon Expressway is writtenNx, and junction on the Olympic Expressway is writtenSx.2 a Na: The travel time of road on the Gangbyeon Expressway changes to . (, )3 b Sb: The travel time of road on the Olympic Expressway changes to . (, )4 c Bc: The travel time of bridge across the Han River changes to . (, )
Output
For each query of type 1, print the answer on its own line. At least one query of type 1 is guaranteed to appear.