#K48792. Marathon Checkpoint Queries

    ID: 28499 Type: Default 1000ms 256MiB

Marathon Checkpoint Queries

Marathon Checkpoint Queries

The city is holding a marathon where each participant (with a unique identifier) passes several checkpoints along the route. At each checkpoint a participant can check in, and if they check in more than once at the same checkpoint, the latest check‐in time overwrites the previous time. After the race, race officials need to query the recorded data to determine statistics for a given participant over a range of checkpoints.

There are two types of queries:

  • Type 1 - Update Checkpoint Time. The query has the format 1 p c t where p is the participant's ID, c is the checkpoint number, and t is the check‐in time. This operation updates the time for participant p at checkpoint c.
  • Type 2 - Query Participant Times. The query has the format 2 p c_1 c_2 q, where p is the participant's ID, c1 and c2 define an inclusive range of checkpoints, and q is a string that is either max or min. Depending on q, you should output the maximum or minimum check‐in time for participant p between checkpoint c1 and checkpoint c2.</p>

    If no check‐in is found for a query, output \( -9223372036854775807 \) for a max query and \( 9223372036854775807 \) for a min query.

    Note: All queries are processed in the order given. The updated value replaces any previous check‐in at the same checkpoint.

    inputFormat

    The first line contains an integer M, the number of queries. Each of the following M lines contains a query. A query can be of two forms:

    1. "1 p c t" – update the check-in time t for participant p at checkpoint c.
    2. "2 p c1 c2 q" – for participant p, report either the maximum (q = max) or minimum (q = min) check-in time over the checkpoints in the inclusive interval from c1 to c2.

    outputFormat

    For each query of Type 2, output a single line with the result. If no checkpoints in the range have been checked in for the given participant, output -9223372036854775807 for a 'max' query and 9223372036854775807 for a 'min' query.## sample

    6
    1 1 2 10
    1 1 3 15
    1 2 3 20
    2 1 2 3 max
    1 1 2 5
    2 1 2 3 min
    15
    

    5

    </p>