#P4666. [BalticOI 2011 Day1] Growing Trees

[BalticOI 2011 Day1] Growing Trees

题目描述

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 cic_i​​ , which determines the number of trees it can be applied to. Moreover, for each bottle there is a minimal height hih_i 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 cic_i​​ smallest trees chosen from the trees that are at least hih_i​​ 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.

输入格式

The first line of the standard input contains two integers NN and MM denoting the number of trees in Egon’s garden and the number of his tasks. The second line contains a sequence of NN integers fromthe range [1,N][1,N] describing the initial heights of the trees in centimeters. The following MM lines describe the tasks in chronological order. Each of those lines begins with a character tit_i (ti=F or C)(t_i=F \ or \ C), which describes the type of the task.

If ti=Ft_i=F then two integers cic_i​​ and hih_i follow. Such a line means that Egon applies a bottle of MegaBoostFertilizer to the cic_i smallest trees among those trees that are at least hih_i​​ centimeters high. When there are less than cic_i​​ trees of sufficient height, he applies the fertilizer to all such trees and discards the bottle with some fertilizer remaining.

If ti=Ct_i=C then two integers mini\min_i​​ and maxi\max_i​​ follow. They denote that Egon has to compute the number of trees whose height HH is between mini\min_i and maxi\max_i​​ centimeters (miniHmaxi)(\min_i \le H \le \max_i).

输出格式

For every task of type C, 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 C tasks in the input.

题目大意

给出一个长度为 NN 的数组 aa,数组中每个数的取值范围均为 [1,N][1,N](没说互不相同)。 接下来有 MM 组操作,操作分为两种:

  1. Fch\texttt{F}\:\:c\:\:h
    将满足 a[i]ha[i] \ge h 的所有 a[i]a[i] 中最小的 cc 个数都 +1+1
  2. Cmaxmin\texttt{C}\:\:max\:\:min
    输出满足 mina[i]maxmin \le a[i] \le maxa[i]a[i] 的个数。

输入格式

第一行有两个整数 NNMM
第二行有 NN 个整数,表示数组 aa
在接下来的 MM 行中,每行有一组操作。

输出格式

对于每组 Cmaxmin\texttt{C}\:\:max\:\:min 操作输出一行,每行一个整数,表示满足 mina[i]maxmin \le a[i] \le maxa[i]a[i] 的个数。

翻译提供者:Planet6174

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

提示

$1 \le N,M \le 10^5,1 \le c \le N,0 \le h \le 10^9,1 \le min \le max \le 10^9$。