#P10689. SuperMemo Memory Game

    ID: 12718 Type: Default 1000ms 256MiB

SuperMemo Memory Game

SuperMemo Memory Game

You are given an initial sequence of numbers \(A_1, A_2, \ldots, A_n\). Then, a series of operations are performed on this sequence. The operations are as follows:

  • ADD x y D: Add \(D\) to each number in the subsequence \(A_x, A_{x+1}, \ldots, A_y\). For example, executing \(\texttt{ADD 2 4 1}\) on \(1, 2, 3, 4, 5\) results in \(1, 3, 4, 5, 5\).
  • REVERSE x y: Reverse the subsequence \(A_x, A_{x+1}, \ldots, A_y\). For example, \(\texttt{REVERSE 2 4}\) on \(1, 2, 3, 4, 5\) results in \(1, 4, 3, 2, 5\).
  • REVOLVE x y T: Rotate the subsequence \(A_x, A_{x+1}, \ldots, A_y\) \(T\) times to the right (cyclic rotation). For example, \(\texttt{REVOLVE 2 4 2}\) on \(1, 2, 3, 4, 5\) results in \(1, 3, 4, 2, 5\).
  • INSERT x P: Insert number \(P\) immediately after position \(x\) (i.e. after \(A_x\)). For example, \(\texttt{INSERT 2 4}\) on \(1, 2, 3, 4, 5\) results in \(1, 2, 4, 3, 4, 5\).
  • DELETE x: Delete the element at position \(x\). For example, \(\texttt{DELETE 2}\) on \(1, 2, 3, 4, 5\) results in \(1, 3, 4, 5\).
  • MIN x y: Query the minimum number in the subsequence \(A_x, A_{x+1}, \ldots, A_y\). For example, \(\texttt{MIN 2 4}\) on \(1, 2, 3, 4, 5\) returns \(2\).

Whenever a MIN query is invoked, output the correct answer.

inputFormat

The first line contains two integers \(n\) and \(m\), representing the number of elements in the initial sequence and the number of operations, respectively.

The second line contains \(n\) integers representing the initial sequence \(A_1, A_2, \ldots, A_n\).

Each of the following \(m\) lines contains an operation in one of the formats described above.

outputFormat

For each MIN query, output a single line with the minimum value in the specified subsequence.

sample

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

</p>