#K46292. Photo Album Operations

    ID: 27944 Type: Default 1000ms 256MiB

Photo Album Operations

Photo Album Operations

You are given a list of photos, each with a unique timestamp and an associated popularity score. You are also given a series of operations to perform on this photo album. There are two types of operations:

  1. Update operation:
    ( U\ t\ new_score ) — Update the popularity score of the photo with timestamp ( t ) to ( new_score ). If there is no photo with timestamp ( t ), ignore the operation.

  2. Query operation:
    ( Q\ start\ end ) — Query the sum of popularity scores for all photos whose timestamps are in the inclusive range ( [start, end] ).

The initial list of photos is provided in sorted order by timestamp. Process the operations sequentially and for each query operation, output the resulting sum on a new line.

inputFormat

The input is read from standard input (stdin) and has the following format:

  • The first line contains an integer ( n ), the number of photos.
  • The next ( n ) lines each contain two integers: the timestamp and the popularity score for a photo.
  • The following line contains an integer ( m ), the number of operations.
  • The next ( m ) lines each describe an operation in one of the following formats:
    • For an update operation: U timestamp new_score
    • For a query operation: Q start end

outputFormat

For each query operation, print the computed sum of popularity scores on a separate line to standard output (stdout).## sample

5
1 10
2 20
3 30
4 40
5 50
3
Q 2 4
U 3 25
Q 2 4
90

85

</p>