Time limit
1s
Memory limit
128 MB
A world-famous oil magnate has a garden with N apple trees. The gardener, Hong Taeseok, performs only two kinds of work: fertilizing trees and reporting statistics about tree heights.
Each bottle of fertilizer has two values C_i and H_i. Applying fertilizer to a tree immediately increases its height by 1 cm. For such a bottle, the gardener considers all trees whose current height is at least H_i cm, chooses C_i distinct trees with the smallest heights among them, and fertilizes each chosen tree once. If fewer than C_i trees satisfy the height condition, he fertilizes all satisfying trees and discards the rest.
A statistics task asks for the number of trees whose heights lie in a given inclusive interval. Given the tasks in chronological order, write a program that answers every statistics task.
The first line contains two integers N and M: the number of trees and the number of tasks.
The second line contains the initial heights of the N trees. Each height is an integer between 1 and N, inclusive.
Each of the next M lines describes one task in chronological order. Each task starts with a character T_i.
F, two integers C_i and H_i follow. Among the trees whose heights are at least H_i cm, fertilize C_i distinct trees with the smallest heights. The same tree cannot be fertilized twice during one task.C, two integers min_i and max_i follow. Count the trees whose height H satisfies min_i <= H <= max_i.The constraints are:
For each task whose type is C, print the number of trees in the requested height interval on its own line.