Under construction

Still being built. Things may change

Real-Time Navigation

Time limit2.5sMemory limit512 MB

Summary
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 O(Elog⁡V)O(E \log V) 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 NN 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 ii on the Gangbyeon Expressway connects junctions N-i and N-(i+1). Road ii on the Olympic Expressway connects junctions S-i and S-(i+1). Bridge ii 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 3N−23N-2 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 NN. (2≤N≤300,0002 \le N \le 300,000)

The second line contains the travel times NiN_i for the N−1N-1 roads on the Gangbyeon Expressway, in order from the west. (1≤Ni≤1,000,000,0001 \le N_i \le 1,000,000,000)

The third line contains the travel times SiS_i for the N−1N-1 roads on the Olympic Expressway, in order from the west. (1≤Si≤1,000,000,0001 \le S_i \le 1,000,000,000)

The fourth line contains the travel times BiB_i for the NN bridges across the Han River, in order from the west. (1≤Bi≤1,000,000,0001 \le B_i \le 1,000,000,000)

The fifth line contains the number of queries QQ. (1≤Q≤300,0001 \le Q \le 300,000)

The next QQ lines each contain one query in one of the following formats.

  • 1 a b: Find the minimum time needed to go from junction aa to junction bb. aa and bb are different. Junction xx on the Gangbyeon Expressway is written Nx, and junction xx on the Olympic Expressway is written Sx.
  • 2 a Na: The travel time of road aa on the Gangbyeon Expressway changes to NaN_a. (1≤a≤N−11 \le a \le N-1, 1≤Na≤1,000,000,0001 \le N_a \le 1,000,000,000)
  • 3 b Sb: The travel time of road bb on the Olympic Expressway changes to SbS_b. (1≤b≤N−11 \le b \le N-1, 1≤Sb≤1,000,000,0001 \le S_b \le 1,000,000,000)
  • 4 c Bc: The travel time of bridge cc across the Han River changes to BcB_c. (1≤c≤N1 \le c \le N, 1≤Bc≤1,000,000,0001 \le B_c \le 1,000,000,000)

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.

Examples2

  1. Example 1

    Input
    7
    1 2 1 1 1 2
    1 1 1 3 3 1
    10 9 7 12 11 8 10
    6
    1 N2 S4
    4 6 2
    1 N3 S5
    3 3 8
    2 4 2
    1 N2 S4
    Expected output
    10
    8
    14
  2. Example 2

    Input
    4
    1 1000000000 1
    1000000000 1 1000000000
    1000000000 1 1 1000000000
    1
    1 N1 N4
    Expected output
    5