This page is still under construction.

Parts of this page are still being built. What you see may change.

Maskpunk 2077

Time limit1sMemory limit1024 MB

Summary
Houses sit on a line with mask costs and edge travel times; handle point updates to travel times and queries for the cheapest mask reachable from a house within m minutes.
Level

Hard8 of 10

Topics
Segment tree, Binary search, Prefix sum, Array
Solved
No attempts yet

Problem

The year is 2077, and the spread of an unending pandemic means every household can make masks at home. Skill varies from person to person, though, so the cost of producing a mask differs from house to house.

In Seogang Village, where NN houses sit in order along a straight line, the household in the ii-th house needs cic_i to make a mask, and moving between the ii-th and (i+1)(i+1)-th houses takes tit_i minutes.

The villagers of Seogang call in to ask what the cheapest mask they can get within mm minutes costs. Juhyeon, who handles phone duties at the city hall, is having a hard time dealing with these calls, because the ever-changing traffic conditions mean the travel times have to be recalculated on the spot.

Juhyeon has asked you to write a program that computes the answers to the villagers' calls. You do not know how to refuse, so you have no choice but to take the request.

Input

The first line gives NN, the number of houses in Seogang Village. (2≤N≤100 0002 \le N \le 100\,000)

The second line gives the mask production costs c1c_1, c2c_2, ......, cNc_N of each household, separated by spaces. (1≤ci≤10 0001 \le c_i \le 10\,000)

The third line gives the initial travel times t1t_1, t2t_2, ......, tN−1t_{N-1}, separated by spaces. (1≤ti≤10 0001 \le t_i \le 10\,000)

The fourth line gives QQ, the number of tasks Juhyeon must handle. (1≤Q≤50 0001 \le Q \le 50\,000)

Each of the next QQ lines gives one task, in order, and each is one of the following two types.

  • UPDATE xx tt : set the travel time between the xx-th and (x+1)(x+1)-th houses to tt minutes. (1≤x≤N−11 \le x \le N - 1, 1≤t≤10 0001 \le t \le 10\,000)
  • CALL xx mm : print the price of the cheapest mask the xx-th house can obtain within mm minutes. (1≤x≤N1 \le x \le N, 1≤m≤1 000 0001 \le m \le 1\,000\,000)

Output

Print the results of the CALL tasks, one per line.

Examples1

  1. Example 1

    Input
    5
    10 17 8 2 16
    2 5 10 6
    5
    CALL 2 4
    CALL 2 5
    UPDATE 2 20
    CALL 2 18
    CALL 2 30
    
    Expected output
    10
    8
    10
    2