#C6418. Book Collection Queries
Book Collection Queries
Book Collection Queries
You are given a collection of n books with associated integer values. Your task is to process q queries on this collection. There are two types of queries:
- Type 1: Swap the books at two given positions.
- Type 2: Find the maximum value among the books in a given range.
For a type 1 query, you are given two indices p1 and p2, and you should swap values[p1-1]
and values[p2-1]
.
For a type 2 query, you are given two indices l and r (satisfying \(1 \leq l \leq r \leq n\)) and you must output the maximum value in the subarray values[l-1...r-1]
.
Process all queries in the order given and output the results for each type 2 query in the order they appear.
inputFormat
The input is given from stdin in the following format:
n q v1 v2 ... vn query1 query2 ... queryq
Where n
is the number of books, q
is the number of queries, v1, v2, ..., vn
are the values of the books, and each query
is represented by three integers. The first integer is the query type (either 1 or 2). For type 1 queries, the next two integers represent positions p1 and p2 to swap. For type 2 queries, the next two integers represent indices l and r (with \(1 \leq l \leq r \leq n\)).
outputFormat
For each type 2 query, output the maximum value in the specified range on a new line to stdout.
## sample5 5
1 5 3 2 4
2 1 5
1 1 5
2 1 3
2 4 5
1 3 4
5
5
2
</p>