#P8937. Sequence Operation Queries

    ID: 22101 Type: Default 1000ms 256MiB

Sequence Operation Queries

Sequence Operation Queries

You are given a sequence \(a\) of length \(n\). You need to support \(m\) operations on this sequence. There are two types of operations:

  • Operation 1: For a given interval \([l, r]\), for each element \(a_i\) where \(a_i > x\) (\(l \le i \le r\)), subtract \(x\) from that element. In other words, perform \(a_i = a_i - x\) if \(a_i > x\).
  • Operation 2: For a given interval \([l, r]\), count the number of elements \(a_i\) such that \(a_i \le x\) (\(l \le i \le r\)).

All indices are 1-indexed.

inputFormat

The first line contains two integers \(n\) and \(m\) separated by a space.

The second line contains \(n\) integers, denoting the elements of the sequence \(a\).

The next \(m\) lines each describe an operation in one of the following formats:

  • For Operation 1: 1 l r x
  • For Operation 2: 2 l r x

outputFormat

For each Operation 2, output a single line containing the count of numbers in the interval \([l, r]\) that are less than or equal to \(x\).

sample

5 5
1 6 3 10 5
2 1 5 5
1 2 4 4
2 1 5 5
1 3 5 3
2 2 4 3
3

4 3

</p>