#K41202. Process Operations on an Integer List

    ID: 26813 Type: Default 1000ms 256MiB

Process Operations on an Integer List

Process Operations on an Integer List

You are given a series of operations to perform on a dynamic list of integers. The operations must be processed sequentially. There are three types of operations:

  1. Insert: A command of the format 1 pos value means insert the integer value at the pos-th position (positions are 1-indexed). If pos is greater than the current length of the list plus one, the integer is appended at the end.
  2. Delete: A command of the format 2 pos indicates that the integer at the pos-th position should be removed from the list.
  3. Sum Query: A command of the format 3 start end requires you to compute the sum of the integers in the list from position start to position end (inclusive). The result of each sum query should be printed on a new line.

Note: All positions use 1-indexing. You can assume that all operations are valid.

The solution must read from stdin and write to stdout.

For example, given the input:

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

The output should be:

8
3

inputFormat

The input is taken from stdin and has the following format:

  1. The first line contains an integer \(n\) representing the number of operations.
  2. The next \(n\) lines each contain a single operation in one of the following formats:
    • 1 pos value — Insert command
    • 2 pos — Delete command
    • 3 start end — Sum Query command

All positions are 1-indexed and it is guaranteed that the operations are valid.

outputFormat

For each "Sum Query" (operation type 3), output the computed sum on a new line to stdout.## sample

5
1 1 5
1 2 3
3 1 2
2 1
3 1 1
8

3

</p>