SOLVE

LATER

Array Insert

Problem

Editorial

Analytics

Gary likes to solve problems of array, but he doesn't like problems that involve queries. His school teacher gave him an assignment full of problems but one of them involve queries. Can you help Gary in solving that problem so that he can go and play with his friends? The problem is :

Given an Array A consisting of N positive integers, you have to answer Q queries on it. Queries can be of the two types: * 1 X Y - Update X at location Y in the array. * 2 L R - Print the sum of range [L, R], i.e. Both L and R are inclusive.

```
Note:- Array indexing is from 0.
```

**Input**:

```
The first line contains two space separated integers N(Length of Array) and Q(Queries).
Next Line contains N space separated integers denoting array A.
Next Q Line contains 3 space separated integers for each line, as described above
```

**Output**:
Answer to the each query of type 2 in a new line, only when range is valid, otherwise ouput `-1`

**Constraints:**
1 <= N <= 10^9
1 <= Q <= 10^5
1 <= A[i], X, Y, L, R <= 10^5

Explanation

```
After First query:
Array becomes 3 3 4 8 9
After Second query:
Sum of range [0, 1] i.e. A[0]+A[1] is 6
After Third query
Sum of range [0, 4] is 27
After Fourth query
Array becomes 3 3 5 8 9
After Fifth query
Sum of range [0, 3] is 19
```

Time Limit:
1.0 sec(s)
for each input file.

Memory Limit:
256 MB

Source Limit:
1024 KB

Marking Scheme:
Marks are awarded when all the testcases pass.

Allowed Languages:
Bash,
C,
C++,
C++14,
Clojure,
C#,
D,
Erlang,
F#,
Go,
Groovy,
Haskell,
Java,
Java 8,
JavaScript(Rhino),
JavaScript(Node.js),
TypeScript,
Julia,
Kotlin,
Lisp,
Lisp (SBCL),
Lua,
Objective-C,
OCaml,
Octave,
Pascal,
Perl,
PHP,
Python,
Python 3,
R(RScript),
Racket,
Ruby,
Rust,
Scala,
Swift,
Swift-4.1,
Visual Basic

Initializing Code Editor...

{"92fae12": "/pagelets/problem-author-tester/algorithm/array-insert/", "4ee1b51": "/pagelets/problems-hint/algorithm/array-insert/", "ea7f6a9": "/pagelets/recommended-problems/algorithm/array-insert/", "c321647": "/pagelets/suggested-problems/algorithm/array-insert/", "e416b81": "/pagelets/show-submission/algorithm/array-insert/"}

realtime.hackerearth.com

80

e073a9a824783aef7365ed28ce5fba4b9b6b2c5b

58a29e5cae2309f04b28

/realtime/pusher/auth/