#K41202. Process Operations on an Integer List
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:
- 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. - Delete: A command of the format
2 pos
indicates that the integer at the pos-th position should be removed from the list. - 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:
- The first line contains an integer \(n\) representing the number of operations.
- The next \(n\) lines each contain a single operation in one of the following formats:
1 pos value
— Insert command2 pos
— Delete command3 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>