#P4117. Sequence Operation Queries
Sequence Operation Queries
Sequence Operation Queries
You are given a sequence \(a\) of length \(n\) and \(m\) operations. There are two types of operations:
- Operation 1: Given \(l, r, x\), for each \(a_i\) with \(l \leq i \leq r\), if \(a_i > x\), update \(a_i = a_i - x\). In other words, subtract \(x\) from every element in the interval \([l, r]\) that is greater than \(x\).
- Operation 2: Given \(l, r, x\), output the number of times \(x\) appears in the subsequence \(a_l, a_{l+1}, \dots, a_r\).
Note: The indexing is 1-based.
inputFormat
The first line contains two integers \(n\) and \(m\): the length of the sequence and the number of operations.
The second line contains \(n\) integers \(a_1, a_2, \dots, a_n\) representing the sequence.
The following \(m\) lines each contain an operation in the format:
op l r x
- If \(op = 1\), perform Operation 1: for every \(a_i\) in the interval \([l, r]\) such that \(a_i > x\), set \(a_i = a_i - x\).
- If \(op = 2\), perform Operation 2: output the count of \(x\) in \(a_l, a_{l+1}, \dots, a_r\).
All values are separated by spaces. The sequence indices are 1-based.
outputFormat
For each operation of type 2, output a single integer representing the count of \(x\) in the specified interval.
sample
5 5
5 3 8 6 3
2 1 5 3
1 2 4 4
2 1 3 4
1 1 5 2
2 1 5 1
2
1
2
</p>