良好对查询AI (CI翻译)
You are given two binary strings $s$ and $t$, both of length $n$.
For two binary strings $a$ and $b$ of the same length, the pair $(a, b)$ is called good if both strings can be made empty by performing the following operation zero or more times:
- Choose a non-empty set of positions
$1 \le i_1 \lt i_2 \lt \ldots \lt i_k \le |a|$and a character$c \in \{\mathtt{0}, \mathtt{1}\}$. - Let
$x = a_{i_1}a_{i_2}\ldots a_{i_k}$and$y = b_{i_1}b_{i_2}\ldots b_{i_k}$. - The character
$c$must be a mode$^{\text{∗}}$of both$x$and$y$. - Delete the characters at the chosen positions from both strings. The remaining characters are concatenated without changing their relative order.
A binary string may have both $\mathtt{0}$ and $\mathtt{1}$ as modes.
You need to answer $q$ queries. In each query, you are given two integers $l$ and $r$. Determine whether the pair of substrings $(s_l s_{l+1} \ldots s_r, t_l t_{l+1} \ldots t_r)$ is good.
The queries are independent.
$^{\text{∗}}$For a binary string $z$, a character $c$ is a mode if it appears at least $\left\lceil \frac{|z|}{2} \right\rceil$ times in $z$. Here, $\lceil x \rceil$ denotes the smallest integer greater than or equal to $x$.
Input
输入格式
AI (CI翻译)Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.
每个测试包含多个测试用例。第一行包含测试用例数量 $t$($1 \le t \le 10^4$)。接下来给出各个测试用例的描述。AI (CI翻译)
The first line of each test case contains two integers $n$ and $q$ ($1 \le n, q \le 2 \cdot 10^5$) — the length of each string and the number of queries.
每个测试用例的第一行包含两个整数 $n$ 和 $q$($1 \le n, q \le 2 \cdot 10^5$)——每个字符串的长度以及询问数量。AI (CI翻译)
The second line of each test case contains the binary string $s$ of length $n$.
第二行包含长度为 $n$ 的二进制字符串 $s$。AI (CI翻译)
The third line of each test case contains the binary string $t$ of length $n$.
第三行包含长度为 $n$ 的二进制字符串 $t$。AI (CI翻译)
Each of the next $q$ lines contains two integers $l$ and $r$ ($1 \le l \le r \le n$) — a query.
接下来的 $q$ 行中,每行包含两个整数 $l$ 和 $r$($1 \le l \le r \le n$)——一个询问。AI (CI翻译)
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
保证所有测试用例的 $n$ 之和不超过 $2 \cdot 10^5$。AI (CI翻译)
It is guaranteed that the sum of $q$ over all test cases does not exceed $2 \cdot 10^5$.
保证所有测试用例的 $q$ 之和不超过 $2 \cdot 10^5$。AI (CI翻译)
Output
输出格式
AI (CI翻译)For each query, output "YES" if the pair $(s_l s_{l+1} \ldots s_r, t_l t_{l+1} \ldots t_r)$ is good. Otherwise, output "NO".
对于每个询问,如果二元组 $(s_l s_{l+1} \ldots s_r, t_l t_{l+1} \ldots t_r)$ 是良好的,输出“YES”;否则输出“NO”。AI (CI翻译)
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
你可以以任意大小写形式输出答案。例如,字符串“yEs”、“yes”、“Yes”和“YES”都会被识别为肯定回答。AI (CI翻译)
Note
说明
AI (CI翻译)In the first test case, for the first query, the pair is $(\mathtt{0}, \mathtt{1})$. No character is a mode of both strings, so no operation can be performed.
在第一个测试用例中,对于第一个询问,二元组为 $(\mathtt{0}, \mathtt{1})$。没有字符同时是两个字符串的众数,因此无法进行任何操作。AI (CI翻译)
For the second query, choose both positions and $c = \mathtt{0}$. Then $x = \mathtt{01}$ and $y = \mathtt{10}$, so $c$ is a mode of both strings and the whole pair is deleted.
对于第二个询问,选择两个位置并令 $c = \mathtt{0}$。此时 $x = \mathtt{01}$,$y = \mathtt{10}$,因此 $c$ 同时是两个字符串的众数,整个二元组都会被删除。AI (CI翻译)
In the third test case, neither character is a mode of both $\mathtt{00011}$ and $\mathtt{01111}$, so the whole pair cannot be deleted in one operation. It can be emptied in three operations:
在第三个测试用例中,$\mathtt{00011}$ 和 $\mathtt{01111}$ 中没有任何字符同时为众数,因此无法通过一次操作删除整个二元组。但可以通过三次操作将其清空:AI (CI翻译)
- Choose positions
$2$and$4$and$c = \mathtt{1}$. Then$x = \mathtt{01}$and$y = \mathtt{11}$, so$c$is a mode of both$x$and$y$. After deleting the selected positions, the remaining characters are concatenated, giving the pair$(\mathtt{001}, \mathtt{011})$. - Choose positions
$1$and$2$and$c = \mathtt{0}$. Then$x = \mathtt{00}$and$y = \mathtt{01}$, so$c$is a mode of both$x$and$y$. After deleting the selected positions, the pair becomes$(\mathtt{1}, \mathtt{1})$. - Choose the remaining position
$1$and$c = \mathtt{1}$. Then$x = \mathtt{1}$and$y = \mathtt{1}$, so$c$is a mode of both$x$and$y$. Deleting the selected position makes both strings empty.
- 选择位置
$2$和$4$,并令$c = \mathtt{1}$。此时$x = \mathtt{01}$,$y = \mathtt{11}$,因此$c$同时是$x$和$y$的众数。删除所选位置后,剩余字符连接起来,得到二元组$(\mathtt{001}, \mathtt{011})$。 - 选择位置
$1$和$2$,并令$c = \mathtt{0}$。此时$x = \mathtt{00}$,$y = \mathtt{01}$,因此$c$同时是$x$和$y$的众数。删除所选位置后,二元组变为$(\mathtt{1}, \mathtt{1})$。 - 选择剩余位置
$1$,并令$c = \mathtt{1}$。此时$x = \mathtt{1}$,$y = \mathtt{1}$,因此$c$同时是$x$和$y$的众数。删除所选位置后,两个字符串都变为空字符串。
样例
3
2 2
01
10
1 1
1 2
5 1
11111
11111
1 3
5 1
00011
01111
1 5
NO
YES
YES
YES
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。