#K61367. Oldest Artifact Finder
Oldest Artifact Finder
Oldest Artifact Finder
You are given a collection of artifacts, each with a unique identifier, a type, and an age. Your task is to process several queries to find the oldest artifact of a given type that falls within a specified age range. An artifact is considered "oldest" if it has the minimum age among all artifacts of that type within the given range. If no artifact meets the criteria for a query, output -1.
The input starts with three integers: n, t, and q, representing the number of artifacts, the number of distinct artifact types, and the number of queries, respectively. Then follow n lines, each containing three integers: identifier, artifact type, and age.
After that, there are q lines of queries. Each query consists of three integers: an artifact type, a lower bound l, and an upper bound u. For each query, you need to output the identifier of the artifact that has the smallest age (i.e. the oldest artifact) among those whose age satisfies \(l \leq age \leq u\). If there is no such artifact, output -1.
Note: All formulas must be in LaTeX format. For example, the condition should be written as \(l \leq age \leq u\).
inputFormat
The first line contains three integers \(n\), \(t\), and \(q\) separated by spaces:
- \(n\): The number of artifacts.
- \(t\): The number of artifact types.
- \(q\): The number of queries.
The next \(n\) lines each contain three integers representing an artifact:
- identifier
- artifact type
- age
Then, the following \(q\) lines each contain three integers:
- artifact type
- lower bound \(l\)
- upper bound \(u\)
All input is provided via standard input (stdin).
outputFormat
For each query, output a single integer on a new line: the identifier of the oldest artifact (i.e. the one with the minimum age) that satisfies \(l \leq age \leq u\). If no artifact meets the criteria, output -1.
Output must be written to standard output (stdout).
## sample5 3 2
123 1 300
124 2 200
125 1 150
126 3 400
127 2 250
1 100 200
2 200 300
125
124
</p>