#K56197. Maximum Power Level Query
Maximum Power Level Query
Maximum Power Level Query
You are given n trees, each producing a fruit of a certain type. You are also provided with an array powerLevels
where the power level for fruit type F is given by \(\text{powerLevels}[F-1]\). Your task is to answer q queries. Each query is represented by three integers \(L\), \(R\), and \(F\) and asks for the maximum power level of fruit type \(F\) among the trees in the range from \(L\) to \(R\) (both inclusive). If there is no tree in the given interval that produces fruit type \(F\), output 0.
Note: The trees are 1-indexed. The answer for a query is simply \(\text{powerLevels}[F-1]\) if there is at least one tree in the given range with fruit type \(F\); otherwise, it is 0.
inputFormat
The first line contains two integers \(n\) and \(q\) separated by a space, where \(n\) is the number of trees, and \(q\) is the number of queries.
The second line contains \(n\) integers representing the fruit types of the trees.
The third line contains \(m\) integers representing the power levels for each fruit type (for fruit types 1 to \(m\), where \(m\) is the maximum fruit type present in the trees).
Each of the next \(q\) lines contains three integers \(L\), \(R\), and \(F\), representing a query.
outputFormat
Print \(q\) integers separated by spaces, where the \(i^{th}\) integer is the answer to the \(i^{th}\) query.
## sample5 3
1 2 1 3 2
3 5 1
1 3 2
2 4 1
1 5 3
5 3 1
</p>