## Maintaining an Array

View as PDF

Points: 7 (partial)
Time limit: 3.0s
Memory limit: 256M

Author:
Problem types

Given a zero-indexed array of integers, perform operations on it.

Operation Defintion
REPLACE i v Replace the integer with .
ROTATELEFT i j Rotate the subarray beginning at and ending at , inclusive, to the left. The integer is now the integer, the integer at index is now the integer at index , et cetera.
ROTATERIGHT i j Rotate the subarray beginning at and ending at , inclusive, to the right. The integer at index is now the integer at index , the integer at index is now the integer at index , et cetera.
FLIP i j Flip the subarray . The integer at index is swapped with the integer at index , with , et cetera.
RANGEUPDATE i j v Set all the elements between and , inclusive, to the integer .
MAX i j v For all elements between and , if the element has a value less than , set it to . Otherwise, increment the element by .
SUM i j Sum up the elements between and , inclusive. Output this value.
CONDITIONALMINSUM i j k Sum up the elements between and , inclusive, that have a value less than or equal to . If there are no elements, the answer is 0. Output this value.
COUNT i j k Count the number of elements between and , inclusive, that have a value of . Output this value.
MAXSUM Find the maximum sum of any subarray in the array. Note that the subarray must not be empty. A subarray of an array is a continuous section of the array. Output this value. , , and .

#### Input Specification

The first line will contain two integers  .

The next line will contain integers, , the initial values of the array.

The next lines will contain an operation as defined above.

#### Output Specification

For each operation that outputs a value, print it on a new line.

There will be no ROTATELEFT, ROTATERIGHT, FLIP, COUNT, or MAXSUM operations.

There wlll be no MAXSUM operations.

No further constraints.

#### Sample Input

4 6
1 2 3 4
SUM 0 3
REPLACE 1 -1
CONDITIONALMINSUM 0 2 1
RANGEUPDATE 2 3 1
MAX 0 3 1
SUM 0 3

#### Sample Output

10
0
7