#K13461. Array Query Processor
Array Query Processor
Array Query Processor
You are given an array of integers of size ( n ). Your task is to process ( q ) queries on the array. There are two types of queries:
- Sum Query (denoted as
S L R
): Compute the sum of elements from index ( L ) to ( R ) (1-indexed). - Update Query (denoted as
U i x
): Update the element at index ( i ) to the new value ( x ).
After processing all queries, output the result for every sum query in the order they appear. Use ( \LaTeX ) format for any formulas.
inputFormat
The input begins with an integer ( n ) representing the number of elements in the array. The next line contains ( n ) space-separated integers, the elements of the array. The third line contains an integer ( q ), the number of queries. This is followed by ( q ) lines where each line represents a query in one of the following formats:
S L R
: A sum query asking for the sum of elements between indices ( L ) and ( R ) (inclusive, 1-indexed).U i x
: An update query that sets the element at index ( i ) to ( x ).
outputFormat
For each sum query, output the result on a new line. If there are no sum queries, no output is produced.## sample
5
1 2 3 4 5
1
S 2 4
9