#P3863. Time-Traveling Array Queries

    ID: 17111 Type: Default 1000ms 256MiB

Time-Traveling Array Queries

Time-Traveling Array Queries

You are given a sequence of n integers and q operations. The operations occur in chronological order with the initial state at second 0 and each subsequent operation at seconds 1 through q.

There are two types of operations:

  • Update: 1 l r x — For every index i in the interval [l, r], add x to ai. Note that x may be negative.
  • Query: 2 p y — At the current time t, determine for how many consecutive past seconds s (starting from t-1 and moving backwards) the value ap was at least y. The current second is not included in the count.

The value of ap at any second t is defined as:

ap(t)=ap(0)+i=1tΔi(p),a_p(t) = a_p(0) + \sum_{i=1}^{t} \Delta_i(p)\,,

where \(\Delta_i(p)\) is the change applied at second \(i\) (if any) to index p.

inputFormat

The first line contains two integers n and q.

The second line contains n integers representing the initial sequence, a1, a2, \ldots, an.

The following q lines each represent an operation, either in the form:

  • 1 l r x (update operation), or
  • 2 p y (query operation).

All indices are 1-indexed.

outputFormat

For each query (operation of type 2), output one line with a single integer representing the number of consecutive seconds (immediately preceding the current second) during which ap was at least y.

sample

5 5
1 2 3 4 5
1 2 4 3
2 3 5
1 1 5 -2
2 4 5
2 5 4
1

3 0

</p>