#K74277. Dynamic Range Sum Operations

    ID: 34162 Type: Default 1000ms 256MiB

Dynamic Range Sum Operations

Dynamic Range Sum Operations

You are given an initially empty list of integers. Your task is to process n operations on this list. There are three types of operations:

  • 1 x: Append the integer x to the end of the list.
  • 2 p: Remove the integer at index p (0-indexed) from the list. If p is invalid (i.e. not in the current list), this operation has no effect.
  • 3 a b: Query and output the sum of the subarray from index a to index b (inclusive). If the indices are out of range or if a > b, output 0.

Formally, let the list be denoted by nums, then the query result is given by:

$$ \text{result} = \begin{cases} \sum_{i=a}^{b} \text{nums}[i] & \text{if } 0 \leq a \leq b < |\text{nums}|, \\ 0 & \text{otherwise.} \end{cases} $$

Process all the operations and for each query operation (the ones starting with 3), print the result on a new line.

inputFormat

The first line of input contains an integer n which stands for the number of operations.

Each of the following n lines contains an operation in one of the following formats:

  • 1 x — append integer x to the list.
  • 2 p — remove the element at index p (0-indexed) from the list.
  • 3 a b — output the sum of elements from index a to b (inclusive).

outputFormat

For each query operation (those starting with 3), output the computed sum on a separate line.

## sample
6
1 5
1 3
1 8
3 0 2
2 1
3 0 1
16

13

</p>