#P2801. Magic of Height Increase
Magic of Height Increase
Magic of Height Increase
The legendary teacher has learned a mysterious magic that can increase a person's height. To demonstrate his power, he gathers N heroes in a line, numbered from \(1\) to \(N\). Initially, each hero's height is a positive integer not exceeding 1000.
The magic can be applied as an operation on any closed interval \([L,R]\) (where \(1 \le L \le R \le N\)). When the magic is cast on the interval \([L,R]\), the height of every hero in that interval increases by an integer \(W\). Note that when \(L = R\), it effectively means increasing the height of a single hero.
However, some skeptics want to verify the power of this magic. They will ask queries of the form: for a given closed interval \([L,R]\) and an integer \(C\), how many heroes in that interval have a height greater than or equal to \(C\)? Your task is to process the magic operations and answer these queries.
Input Format: The first line contains two integers \(N\) and \(Q\), denoting the number of heroes and the number of operations, respectively. The second line contains \(N\) space-separated integers representing the initial heights of the heroes. Then follow \(Q\) lines, each describing an operation in one of the following formats:
1 L R W
— Increase the height of each hero in the interval \([L, R]\) by \(W\).2 L R C
— Query how many heroes in the interval \([L, R]\) have a height greater than or equal to \(C\).
Output Format: For each query operation (type 2), output the result on a new line.
inputFormat
The first line contains two integers, \(N\) and \(Q\) (number of heroes and number of operations).
The second line contains \(N\) integers, where the \(i\)-th integer is the initial height of the \(i\)-th hero.
The following \(Q\) lines each contain an operation in one of the following two formats:
1 L R W
: Increase the heights from index \(L\) to \(R\) by \(W\).2 L R C
: Query the number of heroes in the range \([L,R]\) with height \(\ge C\).
outputFormat
For each query operation (operations of type 2), print the count of heroes whose height is greater than or equal to \(C\) in the specified interval.
sample
3 3
10 20 30
2 1 3 15
1 2 3 5
2 1 3 30
2
1
</p>