#K56762. Travel Time Queries

    ID: 30271 Type: Default 1000ms 256MiB

Travel Time Queries

Travel Time Queries

You are given a sequence of travel times between consecutive checkpoints along a route. The checkpoints are numbered from 1 to \( n \) and there are exactly \( n-1 \) travel time values. Your task is to implement a class TravelTime that supports the following operations:

  1. Query Type 1: Given two checkpoints \( x \) and \( y \) (with \( x < y \)), return the total travel time (i.e. the sum of travel times) from checkpoint \( x \) to checkpoint \( y \).
  2. Query Type 2: Update the travel time between checkpoint \( x \) and checkpoint \( x+1 \) to a new value \( t \).

Additionally, you need to implement a helper function process_queries that reads a list of queries and outputs the results of Query Type 1. When a Query Type 2 is encountered, update the travel times accordingly before processing further queries. The internal implementation may use a prefix sum strategy to compute ranges efficiently. Note that whenever an update occurs, the prefix sum should be recalculated.

inputFormat

The input is provided via stdin and follows this format:

  • The first line contains an integer n representing the total number of checkpoints.
  • The second line contains \( n-1 \) integers representing the travel times between consecutive checkpoints.
  • The third line contains an integer q representing the number of queries.
  • The next q lines each describe a query in one of the following formats:
    • 1 x y: Query Type 1 – output the sum of travel times from checkpoint x to y.
    • 2 x t: Query Type 2 – update the travel time between checkpoint x and x+1 to t.

outputFormat

For each Query Type 1, output the computed total travel time on a new line via stdout. Queries of Type 2 do not produce any output.

## sample
5
3 2 4 5
4
1 1 5
2 2 3
1 1 3
1 3 5
14

6 9

</p>