Joe loves bubble tea. However, he hates spending money, so he always buys the cheapest product. His favourite chain, Bubble tea and me, has a set of bubble tea items with a corresponding price and product number from . They will also occasionally replace items. Their menu displays a set of items with consecutive product numbers from to inclusive. Given the original prices, product replacements and items displayed, find the cheapest bubble tea item available whenever Joe visits the store.
Input Specification
The first line contains two space-separated numbers , the number of bubble tea items and , the amount of operations (product replacements and store visits).
The next lines contain the price of the bubble tea items with the price on line representing the price of item . The price will always be a non-negative integer no greater than .
The next lines contain one operation each. Each operation has the form of either M i x
where product number is replaced with a product with price , or Q l r
indicating products are on display for Joe to buy from.
Output Specification
For each Q
Query, output the cheapest bubble tea item available.
Subtasks
Subtask 1 [30%]
Subtask 2 [70%]
No further restrictions
Sample Input
5 10
35232
390942
649675
224475
18709
Q 2 4
M 5 475689
Q 3 4
Q 2 4
Q 2 3
Q 4 4
Q 3 4
M 3 645514
M 3 680746
Q 1 5
Sample Output
224475
224475
224475
390942
224475
224475
35232
Comments