#K74712. Range Sum and Update Queries

    ID: 34259 Type: Default 1000ms 256MiB

Range Sum and Update Queries

Range Sum and Update Queries

You are given an array of N integers. Your task is to process Q queries on this array. There are two types of queries:

  • q l r: Output the sum of elements from index l to r (1-indexed). In mathematical terms, compute \(\sum_{i=l}^{r} a_i\).
  • u x y: Update the element at index x (1-indexed) to the new value y.

Process the queries in the order they are given. For every sum query (queries starting with q), print the resulting sum on a new line.

inputFormat

The first line contains two space-separated integers N and Q, representing the number of elements in the array and the number of queries respectively. The second line contains N space-separated integers, the initial array elements. Each of the next Q lines contains a query in one of the following formats:

  • "q l r" for a range sum query.
  • "u x y" for an update query, which sets the element at index x to y.

outputFormat

For each query of type "q", output the resulting range sum on a separate line.## sample

5 5
1 2 3 4 5
q 1 3
u 2 10
q 1 3
u 5 20
q 1 5
6

14 38

</p>