Update Subarray Sums


Problem Statement

You are given an array aa of nn integers. You are also given qq queries of the following forms:

  • Type 1: 11 ii vv - update the values of aia_i to become vv
  • Type 2: 22 ll rr - determine the sum of the range ll to rr, i.e. al+al+1+...+ara_l + a_{l+1} + ... + a_r

Input Statement

Your first line will contain two space-separated integers nn and qq. Your next line will contain nn space-separated integers representing aa. Your next qq lines will contain two space-separated integers each representing the queries described.

Output Statement

For each type 2 query you should output a new line containing the sum of the range described.

Constraints

  • 1≤n,q≤1041 \leq n, q \leq 10^4
  • 1≤l≤r≤n1 \leq l \leq r \leq n queries are 11-indexed
  • −109≤ai≤109-10^9 \leq a_i \leq 10^9 (including after updates)

Sample Cases

Input 1
10 5
1 2 3 4 5 6 7 8 9 10
1 5 -10
2 1 10
1 1 1
2 1 10
2 5 6
Output 1
40
40
-4
Explanation 1

After updating a5a_5 to become -10, the array is 1 2 3 4 -10 6 7 8 9 10 The sum from 1 to 10 is 40. Nothing happens when updating a1a_1 to 1. The sum from 1 to 10 is still 40. The sum from 5 to 6 is -10 + 6 = -4.

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.