P3607【USACO 2015 Dec Platinum】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:
1) Given a contiguous interval of fields, add a new haybale to each field.
2) Given a contiguous interval of fields, determine the minimum number of haybales in a field within that interval.
3) Given a contiguous interval of fields, count the total number of haybales inside that interval.
FJ像雇佣几个人在他的农场里帮忙,他需要进行很多种操作,请你帮他搞定。
FJ的农场有N块田地排长一行,编号是从1到N的。每一块田地都有很多草包。FJ要进行下面几种操作:
1)给定一段连续的田地,给每一个田地都增加一些新的草包。
2)给定一段连续的田地,找出草包最少的田地有多少草包。
3)给定一段连续的田地,统计一共有多少草包。
入力形式
The first line contains two positive integers, N (1≤N≤200,000) and Q (1≤Q≤100,000).
The next line contains N nonnegative integers, each at most 100,000, 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≤100,000). 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.
第一行两个整数N(1≤N≤200,000),Q(1≤Q≤100,000)。
第二行有N个非负整数,且不超过100,000,表示每块田地一开始有多少草包。
接下来Q行,每行包含一个大写英文字母和两个数字A,B(1≤A≤B≤N)或三个数字A,B,C(1≤A≤B≤N, 1≤C≤100,000)。这一行包含三个数字当且仅当字母是P。
如果字母是M,输出第A到第B块田地里草包最少的田地的草包数量。
如果字母是P,给第A到第B块田地的每一块田地都增加C个草包。
如果字母是S,输出第A到第B块田地一共有多少草包。
出力形式
A line in the output should appear in response to every 'M' or 'S' entry in FJ's instructions.
对于以字母'M'或'S'的每一行输出一行,表示这一行的答案。
サンプル入力
4 5
3 1 2 4
M 3 4
S 1 3
P 2 3 1
M 3 4
S 1 3
サンプル出力
2
6
3
8