#P10689. SuperMemo

SuperMemo

Problem Description

Your friend, Jackson is invited to a TV show called SuperMemo in which the participant is told to play a memorizing game. At first, the host tells the participant a sequence of numbers, A1,A2,…AnA_1, A_2, \ldots A_n. Then the host performs a series of operations and queries on the sequence which consists:

  • ADD x y D: Add DD to each number in sub-sequence Ax…AyA_x \ldots A_y. For example, performing "ADD 2 4 1" on 1,2,3,4,51, 2, 3, 4, 5 results in 1,3,4,5,51, 3, 4, 5, 5
  • REVERSE x y: reverse the sub-sequence Ax…Ay{A_x \ldots A_y}. For example, performing "REVERSE 2 4" on 1,2,3,4,51, 2, 3, 4, 5 results in 1,4,3,2,51, 4, 3, 2, 5
  • REVOLVE x y T: rotate sub-sequence Ax…Ay{A_x \ldots A_y} TT times. For example, performing "REVOLVE 2 4 2" on 1,2,3,4,51, 2, 3, 4, 5 results in 1,3,4,2,51, 3, 4, 2, 5
  • INSERT x P: insert PP after AxA_x. For example, performing "INSERT 2 4" on 1,2,3,4,51, 2, 3, 4, 5 results in 1,2,4,3,4,51, 2, 4, 3, 4, 5
  • DELETE x: delete AxA_x. For example, performing "DELETE 2" on 1,2,3,4,51, 2, 3, 4, 5 results in 1,3,4,51, 3, 4, 5
  • MIN x y: query the participant what is the minimum number in sub-sequence Ax…AyA_x \ldots A_y. For example, the correct answer to "MIN 2 4" on 1,2,3,4,51, 2, 3, 4, 5 is 22

To make the show more interesting, the participant is granted a chance to turn to someone else that means when Jackson feels difficult in answering a query he may call you for help. You task is to watch the TV show and write a program giving the correct answer to each query in order to assist Jackson whenever he calls.

Input Format

The first line contains nn (n≤100000n \leq 100000).

The following nn lines describe the sequence.

Then follows MM (M≤100000M \leq 100000), the numbers of operations and queries.

The following MM lines describe the operations and queries.

Output Format

For each "MIN" query, output the correct answer.

5
1
2
3
4
5
2
ADD 2 4 1
MIN 4 5
5