#P9069. Sequence Operation Queries
Sequence Operation Queries
Sequence Operation Queries
Given a sequence (a) of length (n), you are required to perform (m) operations. There are two types of operations:
- Update Operation: Given three integers \(l\), \(r\), and \(x\), for every index \(i\) such that \(l \le i \le r\) and \(a_i \neq x\), update \(a_i\) to \(a_i - x\).
- Query Operation: Given two integers \(l\) and \(r\), compute the sum of the elements \(a_i\) for \(l \le i \le r\) that are non-zero.
The operations are given sequentially. For each query operation, output the result on a new line.
inputFormat
The first line contains two integers (n) and (m), representing the length of the sequence and the number of operations respectively. The second line contains (n) space-separated integers denoting the sequence (a). Each of the following (m) lines represents an operation. An operation line with three integers (l), (r), (x) indicates an update operation. An operation line with two integers (l) and (r) indicates a query operation.
outputFormat
For each query operation (lines with two integers), output the calculated sum on a new line. The sum is taken over all (a_i) in the range ([l, r]) such that (a_i \neq 0).
sample
5 5
1 2 3 4 5
1 3 5 2
2 1 3
1 1 5 1
2 2 4
2 4 5
4
3
3
</p>