#K86292. Process Queries on Strings
Process Queries on Strings
Process Queries on Strings
In this problem, you are given a list of strings and a series of queries. There are two types of queries:
- Swap Query: Given in the form 1 x y, swap the strings at positions x and y.
- Minimum Query: Given in the form 2 x y, output the lexicographically smallest string in the subarray from position x to y (both inclusive).
Note that the indices are 1-indexed. You need to process the queries in the given order. For each query of the second type, output the answer on a new line.
The input format is as follows:
- The first line contains an integer $n$, the number of strings.
- The second line contains $n$ strings separated by spaces.
- The third line contains an integer $q$, the number of queries.
- The following $q$ lines contain one query each.
The output should include one line per query of type 2, corresponding to the lexicographically smallest string found in the given range.
inputFormat
The input is given via standard input (stdin) in the following format:
n s1 s2 ... sn q query1 query2 ... queryq
Here, n is the number of strings. Each query is either of the form "1 x y" for swapping or "2 x y" for outputting the minimum string in the subarray between x and y (inclusive). All indices are 1-indexed.
outputFormat
For each query of type 2 (the minimum query), print the lexicographically smallest string in the specified range on a separate line. The output is sent to standard output (stdout).## sample
5
banana apple cherry date elderberry
4
2 1 3
1 2 4
2 1 3
2 1 5
apple
banana
apple
</p>