#P12009. Binary String Equivalence under Interval Flips
Binary String Equivalence under Interval Flips
Binary String Equivalence under Interval Flips
You are given n binary strings (each of length m) consisting of characters '0' and '1'. We define an interval pair as a pair \((l,r)\) satisfying \(1 \le l \le r \le m\). An interval set \(S\) is a set composed of such interval pairs.
For a binary string \(a\) and an interval set \(S\), a flip operation is defined as choosing an interval \((l,r) \in S\) and flipping every bit in \(a\) in positions from \(l\) to \(r\) (i.e. for each \(i \in [l,r]\), assign \(a_i \leftarrow a_i \oplus 1\), where \(\oplus\) denotes the bitwise XOR operation).
We say that two binary strings \(a\) and \(b\) are equivalent under \(S\) if it is possible to transform \(a\) into \(b\) using zero or more flip operations as defined above (note that flip operations may be repeated and performed in any order).
Initially, the interval set \(S\) is empty. You are then given a total of \(q\) operations. Each operation is one of the following:
- Insertion operation: Given an interval pair \((l,r)\), update \(S \leftarrow S \cup \{(l,r)\}\).
- Query operation: Given two indices \(x\) and \(y\), determine whether the \(x\)th binary string and the \(y\)th binary string are equivalent under the current interval set \(S\).
Note: Two strings \(a\) and \(b\) are equivalent if and only if their bitwise XOR \(a \oplus b\) can be expressed as a (finite) XOR of some of the interval vectors corresponding to the intervals inserted into \(S\). An interval \((l,r)\) corresponds to a binary vector of length \(m\) which has 1's in every position \(i\) with \(l \le i \le r\) and 0's elsewhere.
inputFormat
The first line contains three integers \(n\), \(m\), and \(q\) representing the number of binary strings, the length of each string, and the number of operations respectively.
The next \(n\) lines each contain a binary string of length \(m\) (each string consists only of characters '0' and '1').
Then, \(q\) lines follow. Each line represents an operation in one of the following formats:
1 l r
— Insertion operation: insert the interval pair \((l,r)\) into \(S\).2 x y
— Query operation: check if the \(x\)th and \(y\)th binary strings are equivalent under the current \(S\).
It is guaranteed that the operations are valid. The indices for binary strings are 1-indexed.
outputFormat
For each query operation, output a single line containing either YES
if the two strings are equivalent under the current interval set \(S\), or NO
otherwise.
sample
2 3 3
010
101
2 1 2
1 1 3
2 1 2
NO
YES
</p>