Sequence and Queries 24

Time limit1sMemory limit512 MB

Summary
Maintain an array under point updates and range queries that ask for the largest sum of two distinct elements within a subarray.
Level

Hard8 of 10

Topics
Segment tree, Dynamic programming, Greedy, Implementation
Solved
No attempts yet

Problem

A sequence A1,A2,…,ANA_1, A_2, \ldots, A_N of length NN is given. Write a program that performs the following queries.

  • 1 i v: change AiA_i to vv. (1≤i≤N1 \le i \le N, 1≤v≤1091 \le v \le 10^9)
  • 2 l r: among all Ai+AjA_i + A_j with l≤i<j≤rl \le i < j \le r, print the maximum value. (1≤l<r≤N1 \le l < r \le N)

Indices of the sequence start at 1.

Input

The first line gives the size of the sequence NN. (2≤N≤100,0002 \le N \le 100{,}000)

The second line gives A1,A2,…,ANA_1, A_2, \ldots, A_N. (1≤Ai≤1091 \le A_i \le 10^9)

The third line gives the number of queries MM. (2≤M≤100,0002 \le M \le 100{,}000)

Each of the next MM lines gives one query.

Output

For each type 2 query, print the answer on its own line in order.

Examples1

  1. Example 1

    Input
    5
    5 4 3 2 1
    6
    2 2 4
    2 1 4
    1 5 5
    2 3 5
    1 4 9
    2 3 5
    
    Expected output
    7
    9
    8
    14