#SGM0000071. Truy vấn đoạn và bản sao (Range Queries and Copies)

Truy vấn đoạn và bản sao (Range Queries and Copies)

Range Queries and Copies

Source: CSES

Version: Phuoc Hung OJ Extended

Problem

Initially the list contains one array. Operation 1 k a x changes position aa of array kk to xx; 2 k a b asks its range sum; 3 k appends an independent copy of array kk.

Input

The first line contains n,qn,q, followed by the initial array and qq operations.

Output

Print the answer to every type-2 operation.

Subtasks

Subtask 1 (20%)

  • n≤30n\le 30, number of queries ≤30\le 30.
  • All other conditions are the same as Subtask 3.

Subtask 2 (30%)

  • n≤3000n\le 3000, number of queries ≤3000\le 3000.
  • All other conditions are the same as Subtask 3.

Subtask 3 (50%)

  • 1≤n,q≤2⋅1051\le n,q\le2\cdot10^5
  • 1≤ti,x≤1091\le t_i,x\le10^9
  • 1≤a≤b≤n1\le a\le b\le n
  • every version index refers to an existing array

Example

Input

5 6
2 3 1 2 5
3 1
2 1 1 5
2 2 1 5
1 2 2 5
2 1 1 5
2 2 1 5

Output

13
13
13
15

Explanation

After copying array 1, updating position 2 of array 2 changes only that copy. Their full sums become 1313 and 1515.