loj#P2630. 「BalticOI 2011 Day1」种树 Growing Trees
「BalticOI 2011 Day1」种树 Growing Trees
Description
For fertilizing the trees he has several bottles of MegaBoostFertilizer, which, when treated on trees, causes them to grow one centimeter up instantly. Every bottle has a limited capacity , which determines the number of trees it can be applied to. Moreover, for each bottle there is a minimal height of trees, which can be treated with it. Since Egon wants to have all his trees as big as possible, he always applies the fertilizer to the smallest trees chosen from the trees that are at least centimeters high.
When Egon computes statistics about trees he has to determine the number of trees whose height is in some given interval. Egon is quite busy working in the garden, so he asked you to write a program, that given the list of his tasks, computes the statistics for him.
Input
The first line of the standard input contains two integers and denoting the number of trees in Egon’s garden and the number of his tasks. The second line contains a sequence of integers fromthe range describing the initial heights of the trees in centimeters. The following lines describe the tasks in chronological order. Each of those lines begins with a character (), which describes the type of the task.
If then two integers and follow. Such a line means that Egon applies a bottle of MegaBoostFertilizer to the smallest trees among those trees that are at least centimeters high. When there are less than trees of sufficient height, he applies the fertilizer to all such trees and discards the bottle with some fertilizer remaining.
If then two integers and follow. They denote that Egon has to compute the number of trees whose height is between and centimeters ( ).
Output
For every task of type , output one line containing the number of apple trees that have the required height. The order of the results should conform to the order of type tasks in the input.
5 7
1 3 2 5 2
F 2 1
C 3 6
F 2 3
C 6 8
F 2 1
F 2 2
C 3 5
3
0
5
Constraints
$1 ≤ N,M ≤ 10^5, 1 ≤ c ≤ N, 0 ≤ h ≤ 10^9, 1 ≤\ min ≤ \max ≤ 10^9$