PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SRD0000113. Chef và Churu (Chef and Churu)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Chef và Churu (Chef and Churu)

Chef and Churu

Source: CodeChef

Version: Phuoc Hung OJ Extended

Problem Statement

Chef has an array of NN positive integers A1,…,ANA_1,\ldots,A_N. He defines exactly NN functions:

$$F_i(A)=\sum_{j=L_i}^{R_i} A_j \qquad(1\le i\le N).$$

The intervals [Li,Ri][L_i,R_i] never change; only the values in AA may change.

Process QQ operations in their given order:

  • 1 x y: assign Ax:=yA_x:=y (this is not an increment).
  • 2 m n: calculate Fm(A)+Fm+1(A)+⋯+Fn(A)F_m(A)+F_{m+1}(A)+\cdots+F_n(A) using the current array.

An array value may contribute to multiple functions. The answer can exceed the maximum signed 64-bit integer.

Input

  • The first line contains NN.
  • The second line contains A1,…,ANA_1,\ldots,A_N.
  • The next NN lines give Li,RiL_i,R_i for each function FiF_i.
  • The next line contains QQ.
  • The final QQ lines are operations 1 x y or 2 m n.

All indices are 1-based. The parameters m n of a type-2 operation refer to function indices, not array positions.

Output

For each operation of type 2, output the requested sum on its own line as a decimal integer, without a modulus.

Subtasks

  • Subtask 1 (10 points, official): 1≤N≤1 0001\le N\le1\,000, 1≤Q≤1 0001\le Q\le1\,000; 1≤Ai,y≤1091\le A_i,y\le10^9; 1≤Li≤Ri≤N1\le L_i\le R_i\le N; an update has 1≤x≤N1\le x\le N, and a type-2 query has 1≤m≤n≤N1\le m\le n\le N.

  • Subtask 2 (10 points, official): 1≤N,Q≤1051\le N,Q\le10^5; 1≤Ai,y≤1091\le A_i,y\le10^9; 1≤Li≤Ri≤N1\le L_i\le R_i\le N and Ri−Li≤10R_i-L_i\le10 for every function; all positions xx used in type-1 updates are pairwise distinct; type-2 queries have 1≤m≤n≤N1\le m\le n\le N.

  • Subtask 3 (80 points, official): 1≤N,Q≤1051\le N,Q\le10^5; 1≤Ai,y≤1091\le A_i,y\le10^9; 1≤Li≤Ri≤N1\le L_i\le R_i\le N; type-1 positions xx can repeat, and type-2 queries have 1≤m≤n≤N1\le m\le n\le N.

Examples

Example 1

Input

5
1 2 3 4 5
1 3
2 5
4 5
3 5
1 2
4
2 1 4
1 3 7
2 1 4
2 3 5

Output

41
53
28

Explanation

Initially F1=6,F2=14,F3=9,F4=12,F5=3F_1=6,F_2=14,F_3=9,F_4=12,F_5=3, hence the first answer is 4141. After assigning A3=7A_3=7, these become 10,18,9,16,310,18,9,16,3; the next answers are 5353 and 2828.