P18097 [CCPC 2026 Changchun] Kingdom of XOR

Background

Another XOR problem? Is your school a kingdom of XOR?

Description

You are given two `01` strings $A,B$ of length $n$, and $m$ reversal intervals $[l_1,r_1],[l_2,r_2],\dots,[l_m,r_m]$. For a given positive integer $k$, consider the following problem: - Define one operation as: choose a reversal interval $[l_i,r_i]$ **other than $[l_k,r_k]$**, and reverse (flip) the `01` characters of $A$ at the positions inside the interval $[l_i,r_i]$ (that is, change `0` to `1` and change `1` to `0`). Then, is it possible to transform $A$ into $B$ using finitely many operations? Solve the above problem for $k=1,2,\dots,m$ respectively.

Input Format

The first line of the input contains a single positive integer $T$ ($1\le T \le 1000$), representing the number of test cases. For each test case, the first line contains two positive integers $n,m$ ($1\le n,m\le 2\times 10^5$), representing the length of $A,B$ and the number of reversal intervals; The second line contains a `01` string $A$ of length $n$, representing the initial `01` string. The third line contains a `01` string $B$ of length $n$, representing the target `01` string. The next $m$ lines, the $i$-th of which contains two positive integers $l_i,r_i$ ($1\le l_i\le r_i\le n$), represent a reversal interval $[l_i,r_i]$. It is guaranteed that any two input intervals are different, that is, there do not exist $i\ne j$ with $(l_i,r_i)=(l_j,r_j)$. It is guaranteed that the sum of $n$ and the sum of $m$ over all testdata in a single test point do not exceed $2\times 10^5$ respectively.

Output Format

For each test case, output one line with a `01` string $S$ of length $m$, where: - If $A$ can be transformed into $B$ using finitely many operations when the forbidden reversal interval has index $k=i$, then $S_i=\,$`1`; otherwise $S_i=\,$`0`.

Explanation/Hint

For the first test case, the $i$-th reversal interval only reverses the character at position $i$. After choosing the $2$-nd and then the $4$-th reversal interval, $A$ can be transformed into $B$, so $S_1=S_3=\,$`1`. However, forbidding either of these two reversal intervals makes the corresponding character of $A$ impossible to become `1`, so $A$ cannot be transformed into $B$, and therefore $S_2=S_4=\,$`0`. For the second test case, choosing the $1$-st reversal interval, or choosing the $2$-nd and then the $5$-th reversal interval, transforms $A$ into $B$, so all characters in $S$ are `1`. Translated by QwenWork