#K15791. Stream Query Operations

    ID: 24435 Type: Default 1000ms 256MiB

Stream Query Operations

Stream Query Operations

You are given an array (or stream) of n integers. Your task is to process q queries on this array. There are two types of queries:

  • Update Query: In the form "1 index value", update the element at position index to the new value.
  • Frequency Query: In the form "2 left right value", determine the frequency of the given value in the segment of the array from index left to right (both inclusive).

Note: The array is 1-indexed. For every frequency query, output the result on a new line.

Mathematically, for a frequency query, compute \[ \text{result} = \left| \{ i \mid left \le i \le right \text{ and } a_i = value \} \right| \]

inputFormat

The first line contains two integers, n and q, where n is the number of elements in the array and q is the number of queries.

The second line contains n space-separated integers representing the array.

Each of the following q lines represents a query. A query is given in one of the following two formats:

  • "1 index value" for an update query.
  • "2 left right value" for a frequency query.

outputFormat

For each frequency query (query type 2), output a single integer representing the count of occurrences of the specified value in the given range. Each result should be printed on a new line.

## sample
6 5
1 2 1 3 2 1
2 1 6 1
1 3 2
2 1 6 1
2 1 4 2
2 3 5 3
3

2 2 1

</p>