#K80872. Sequence Update and Range Sum Query

    ID: 35627 Type: Default 1000ms 256MiB

Sequence Update and Range Sum Query

Sequence Update and Range Sum Query

You are given an initially empty sequence of integers. The sequence supports two types of operations:

  • set x y: Set the value of the x-th integer in the sequence to y.
  • sum l r: Calculate and output the sum of the integers from position l to r (both inclusive). If an index was never set, it is considered to be 0.

The operations are provided in order, and the sequence should be updated accordingly. Your task is to process these operations and for every sum query, output the resulting sum.

Note: The indices are positive integers. You must read the input from stdin and write the output to stdout.

inputFormat

The first line contains a single integer Q indicating the total number of operations.

The following Q lines each contain an operation in one of the following formats:

  • set x y — Set the x-th integer to y.
  • sum l r — Output the sum of integers from index l to r (inclusive).

All values are separated by spaces.

outputFormat

For each sum operation, print the computed sum on a new line to stdout.

## sample
6
set 1 5
set 2 3
sum 1 2
set 3 2
sum 1 3
sum 2 3
8

10 5

</p>