#C7008. Race Event Queries
Race Event Queries
Race Event Queries
During a race event, you are given N checkpoints, each with a certain number of tasks. You need to process Q queries of two types: update the number of tasks at a specific checkpoint, or compute the total number of tasks in a given range of checkpoints.
There are two types of queries:
- 1 i t: Update the number of tasks at the i-th checkpoint to t.
- 2 l r: Query the sum of tasks from checkpoint l to checkpoint r (inclusive).
All indices are 1-indexed. For each query of type 2, you need to output the sum of tasks in the specified range on a new line.
This problem requires an efficient data structure that can handle range sum queries and point updates, such as a Fenwick tree.
inputFormat
The input is given via stdin and is structured as follows:
- The first line contains two integers N and Q representing the number of checkpoints and the number of queries, respectively.
- The second line contains N integers indicating the number of tasks at each checkpoint.
- The following Q lines each contain a query in one of the following formats:
- 1 i t: Update the i-th checkpoint to have t tasks.
- 2 l r: Output the sum of tasks from checkpoint l to r.
outputFormat
For each query of type 2, print the result (the sum of tasks in the given range) on a new line. Output is written to stdout.
## sample5 3
2 5 3 8 6
2 2 4
1 3 10
2 1 5
16
31
</p>