#P2801. 教主的魔法

教主的魔法

Description

{{The leader has recently learned a magical spell that can make people taller. He plans to demonstrate it to every hero in the XMYZ Information Group. Thus, NN heroes gather once again, lining up in a row and being numbered 1,2,,N1, 2, \ldots, N.

Each person’s height is initially a positive integer not exceeding 10001000. Each time the leader casts the spell, he can add an integer WW to the heights of all heroes in the closed interval [L,R][L, R] (1LRN1≤L≤R≤N). (Although L=RL=R is not standard interval notation, we can regard it as increasing only the height of the LL-th hero.)

CYZ, Guang Ge, and ZJQ do not believe in the leader’s magic, so they sometimes ask WD how many heroes in the closed interval [L,R][L, R] have height greater than or equal to CC, to verify whether the magic really works.

WD is extremely lazy, so he hands this task over to you.}}

Input Format

{{The first line contains two integers N,QN, Q. QQ is the total number of queries and spells.

The second line contains NN positive integers; the ii-th number is the height of the ii-th hero.

Lines 33 through Q+2Q+2 each contain one operation:

  1. If the first letter is M, then three numbers L,R,WL, R, W follow. Add WW to the heights of all heroes in the closed interval [L,R][L, R].

  2. If the first letter is A, then three numbers L,R,CL, R, C follow. Query how many heroes in the closed interval [L,R][L, R] have height greater than or equal to CC.}}

Output Format

{{For each A query, output one line containing a single integer: the number of heroes with height greater than or equal to CC in [L,R][L, R].}}

5 3
1 2 3 4 5
A 1 5 4
M 3 5 1
A 1 5 4
2
3

Hint

{{Sample explanation:

Originally, the 55 heroes’ heights are 1,2,3,4,51, 2, 3, 4, 5, so there are 22 heroes in [1,5][1, 5] whose heights are at least 44. After the leader casts the spell, the heights become 1,2,4,5,61, 2, 4, 5, 6, so there are 33 heroes in [1,5][1, 5] whose heights are at least 44.

Constraints:

  • For 30%30\% of the testdata, N1000N≤1000, Q1000Q≤1000.
  • For 100%100\% of the testdata, N106N≤10^6, Q3000Q≤3000, 1W10001≤W≤1000, 1C1091≤C≤10^9.

upd 2022.8.18\text{upd 2022.8.18}: A new set of Hack testdata has been added. upd 2023.8.16\text{upd 2023.8.16}: A new set of Hack testdata has been added.}}

Translated by ChatGPT 5