Problem10276--CF EDU - Segment Tree P1 - Step 4 - A. Sign alternation

10276: CF EDU - Segment Tree P1 - Step 4 - A. Sign alternation

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 512 MiB

Description

Implement data structure of $n$ elements $a_1,a_2…a_n$, with the following operations:

  • assign the element $a_i$ value $j$;
  • find alternating sign sum in the range from $l$ to $r$ inclusive $(a_l−a_{l+1}+a_{l+2}−…±a_r)$.

Input

The first line of the input file contains a natural number $n\ (1≤n≤10^5)$ — the length of the array. 

The second line contains the initial values of the elements (non-negative integers not exceeding $10^4$).

The third line contains a positive integer $m\ (1≤m≤10^5)$ — the number of operations. 

The following $m$ lines contain operations:

  • the operation of the first type is given by three numbers $\text{0 i j}\ (1≤i≤n,\ 1≤j≤10^4)$.
  • an operation of the second type is given by three numbers $\text{1 l r}\ (1≤l≤r≤n)$.

Output

For each operation of the second type, print on a separate line the corresponding sign alternating sum.

Sample 1 Input

3
1 2 3
5
1 1 2
1 1 3
1 2 3
0 2 1
1 1 3

Sample 1 Output

-1
2
-1
3

HINT

CF EDU.

Source/Category