#K89007. Array Query Processor

    ID: 37434 Type: Default 1000ms 256MiB

Array Query Processor

Array Query Processor

You are given an array consisting of N integers where each element is either 0 or 1. You need to process Q queries on this array. There are three types of queries:

  • 1 X: Set the Xth element of the array to 1.
  • 2 X: Set the Xth element of the array to 0.
  • 3 L R: Count the number of 1's in the subarray from index L to R (inclusive) and output the result.

The queries are applied sequentially and the update operations (queries of type 1 and 2) modify the array for subsequent queries. Formally, for a query of type 3, you need to output the value

result=i=LRai,\text{result} = \sum_{i=L}^{R} a_i,

where a_i is the ith element of the array after processing all previous queries.

Note: The array is 1-indexed.

inputFormat

The input is given via stdin and has the following format:

  1. The first line contains two integers N and Q, where N is the length of the array and Q is the number of queries.
  2. The second line contains N space-separated integers (each 0 or 1) representing the initial state of the array.
  3. The following Q lines each describe a query. A query is either in the format 1 X, 2 X, or 3 L R as described above.

outputFormat

For each query of type 3, output the result (i.e. the number of 1's in the specified subarray) on a new line to stdout.

## sample
5 5
0 1 0 1 0
3 1 5
1 3
3 1 5
2 2
3 1 5
2

3 2

</p>