Counting Haybales
Farmer John is trying to hire contractors to help rearrange his farm, but so far all of them have quit when they saw the complicated sequence of instructions FJ wanted them to follow. Left to complete the project by himself, he realizes that indeed, he has made the project perhaps more complicated than necessary. Please help him follow his instructions to complete the farm upgrade.
FJ's farm consists of n fields in a row, conveniently numbered 1..n. In each field there can be any number of haybales. Farmer John's instructions contain three types of entries:
Given a contiguous interval of fields, add a new haybale to each field.
Given a contiguous interval of fields, determine the minimum number of haybales in a field within that interval.
Given a contiguous interval of fields, count the total number of haybales inside that interval.
Input
The first line contains two positive integers n (1 ≤ n ≤ 2 * 10^5
) and q (1 ≤ q ≤ 10^5
).
The next line contains n nonnegative integers, each at most 10^5
, indicating how many haybales are initially in each field.
Each of the next q lines contains a single uppercase letter, either M, P or S, followed by either two positive integers a and b (1 ≤ a ≤ b ≤ n), or three positive integers a, b and c (1 ≤ a ≤ b ≤n, 1 ≤ c ≤ 10^5
). There will be three positive integers if and only if the uppercase letter is P.
If the letter is M, print the minimum number of haybales in the interval of fields from a..b.
If the letter is P, put c new haybales in each field in the interval of fields from a..b.
If the letter is S, print the total number of haybales found within interval of fields from a..b.
Output
A line in the output should appear in response to every M or S entry in FJ's instructions.