#SGM0000004. RMQ với phép dịch vòng (RMQ with Shifts)
RMQ với phép dịch vòng (RMQ with Shifts)
RMQ with Shifts
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
Given a 1-indexed array , process two operation types. query(L,R) asks for the minimum on . shift(i_1,i_2,\ldots,i_k) with left-cyclically shifts the values at those positions.
Input
- The first line contains and .
- The second line contains positive integers, each at most .
- Each of the next lines is a valid
query(...)orshift(...)string, contains no spaces, and has length at most .
Output
For every query operation, print the minimum value in the requested range.
Subtasks
- Subtask 1 — 20%: .
- Subtask 2 — 30%: .
- Subtask 3 — 50%: , .
Examples
Input
7 5
6 2 4 8 5 1 4
query(3,7)
shift(2,4,5,7)
query(1,4)
shift(1,2)
query(2,2)
Output
1
4
6
Explanation
The first query examines , so the answer is . After shift(2,4,5,7), the array becomes , hence query(1,4) returns . After shift(1,2), the first two values become , so query(2,2) returns .