#P5057. Bit Flipping and Query
Bit Flipping and Query
Bit Flipping and Query
You are given an array of n elements, initially all set to 0. You have m operations to perform on the array. There are two types of operations:
1. Flip Operation: Given two indices x and y (1-indexed), flip every element in the subarray from index x to y. In other words, every 0 becomes 1 and every 1 becomes 0. Formally, for every index i in [x,y], update the element as follows: $$a_i = 1 - a_i.$$
2. Query Operation: Given an index i (1-indexed), output the current value at that position.
For example, when n = 20, a sequence of 10 operations might be performed as illustrated in the image.
inputFormat
The first line contains two integers n and m where \(1 \leq n, m \leq 10^5\).
The next m lines contain the operations. Each operation is in one of the following formats:
1 x y
— Flip the subsequence from the xth to yth element (inclusive).2 i
— Query the value at the ith element.
It is guaranteed that the indices provided are valid for the array.
outputFormat
For each query operation (type 2), output the current value at the queried index on a separate line.
sample
5 3
1 2 4
2 3
2 1
1
0
</p>