309879: CF1750C. Complementary XOR

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Complementary XOR

题意翻译

你有两个 $\tt{01}$ 串 $a,b$,长度均为 $n$。你可以使用不超过 $n+5$ 次下面这种操作: - 你选择两个下标 $l,r(1\le l\le r\le n)$。 - 对于所有的 $i\in[l,r]$,取反 $a_i$(也就是说,$a_i\gets1-a_i$,下面同理)。 - 对于所有的 $i\in[1,l)\cup(r,n]$,取反 $b_i$。 现在你的任务是判断是否可以通过使用不超过 $n+5$ 次这种操作让两个串里的所有元素都变成 $\tt0$。如果可以,输出一种可能的方案。可以证明,如果使用任意次操作可以达成目标,那么至少存在一种方案可以在 $n+5$ 次操作内达成目标。 $n\ge 2$,$\sum n\le 2\times10^5$。

题目描述

You have two binary strings $ a $ and $ b $ of length $ n $ . You would like to make all the elements of both strings equal to $ 0 $ . Unfortunately, you can modify the contents of these strings using only the following operation: - You choose two indices $ l $ and $ r $ ( $ 1 \le l \le r \le n $ ); - For every $ i $ that respects $ l \le i \le r $ , change $ a_i $ to the opposite. That is, $ a_i := 1 - a_i $ ; - For every $ i $ that respects either $ 1 \le i < l $ or $ r < i \le n $ , change $ b_i $ to the opposite. That is, $ b_i := 1 - b_i $ . Your task is to determine if this is possible, and if it is, to find such an appropriate chain of operations. The number of operations should not exceed $ n + 5 $ . It can be proven that if such chain of operations exists, one exists with at most $ n + 5 $ operations.

输入输出格式

输入格式


Each test consists of multiple test cases. The first line contains a single integer $ t $ ( $ 1 \leq t \leq 10^5 $ ) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $ n $ ( $ 2 \le n \le 2 \cdot 10^5 $ ) — the length of the strings. The second line of each test case contains a binary string $ a $ , consisting only of characters 0 and 1, of length $ n $ . The third line of each test case contains a binary string $ b $ , consisting only of characters 0 and 1, of length $ n $ . It is guaranteed that sum of $ n $ over all test cases doesn't exceed $ 2 \cdot 10^5 $ .

输出格式


For each testcase, print first "YES" if it's possible to make all the elements of both strings equal to $ 0 $ . Otherwise, print "NO". If the answer is "YES", on the next line print a single integer $ k $ ( $ 0 \le k \le n + 5 $ ) — the number of operations. Then $ k $ lines follows, each contains two integers $ l $ and $ r $ ( $ 1 \le l \le r \le n $ ) — the description of the operation. If there are several correct answers, print any of them.

输入输出样例

输入样例 #1

5
3
010
101
2
11
10
4
1000
0011
2
10
10
3
111
111

输出样例 #1

YES
1
2 2
NO
NO
YES
2
1 2
2 2
YES
2
1 1
2 3

说明

In the first test case, we can perform one operation with $ l = 2 $ and $ r = 2 $ . So $ a_2 := 1 - 1 = 0 $ and string $ a $ became equal to 000. $ b_1 := 1 - 1 = 0 $ , $ b_3 := 1 - 1 = 0 $ and string $ b $ became equal to 000. In the second and in the third test cases, it can be proven that it's impossible to make all elements of both strings equal to $ 0 $ . In the fourth test case, we can perform an operation with $ l = 1 $ and $ r = 2 $ , then string $ a $ became equal to 01, and string $ b $ doesn't change. Then we perform an operation with $ l = 2 $ and $ r = 2 $ , then $ a_2 := 1 - 1 = 0 $ and $ b_1 = 1 - 1 = 0 $ . So both of string $ a $ and $ b $ became equal to 00. In the fifth test case, we can perform an operation with $ l = 1 $ and $ r = 1 $ . Then string $ a $ became equal to 011 and string $ b $ became equal to 100. Then we can perform an operation with $ l = 2 $ and $ r = 3 $ , so both of string $ a $ and $ b $ became equal to 000.

Input

题意翻译

你有两个 $\tt{01}$ 串 $a,b$,长度均为 $n$。你可以使用不超过 $n+5$ 次下面这种操作: - 你选择两个下标 $l,r(1\le l\le r\le n)$。 - 对于所有的 $i\in[l,r]$,取反 $a_i$(也就是说,$a_i\gets1-a_i$,下面同理)。 - 对于所有的 $i\in[1,l)\cup(r,n]$,取反 $b_i$。 现在你的任务是判断是否可以通过使用不超过 $n+5$ 次这种操作让两个串里的所有元素都变成 $\tt0$。如果可以,输出一种可能的方案。可以证明,如果使用任意次操作可以达成目标,那么至少存在一种方案可以在 $n+5$ 次操作内达成目标。 $n\ge 2$,$\sum n\le 2\times10^5$。

Output

**题意翻译**

你有两个01字符串a,b,长度均为n。你可以使用不超过n+5次下面这种操作:

- 你选择两个下标l,r(1≤l≤r≤n)。
- 对于所有的i∈[l,r],取反ai(也就是说,ai→1−ai,下面同理)。
- 对于所有的i∈[1,l)∪(r,n],取反bi。

现在你的任务是判断是否可以通过使用不超过n+5次这种操作让两个串里的所有元素都变成0。如果可以,输出一种可能的方案。可以证明,如果使用任意次操作可以达成目标,那么至少存在一种方案可以在n+5次操作内达成目标。

n≥2,∑n≤2×10^5。

**题目描述**

你有两个二进制字符串a和b,长度为n。你想让这两个字符串的所有元素都等于0。不幸的是,你只能使用以下操作来修改这些字符串的内容:

- 你选择两个索引l和r(1≤l≤r≤n);
- 对于每个满足l≤i≤r的i,将ai更改为相反数。也就是说,ai:=1−ai;
- 对于每个满足1≤i
你的任务是判断这是否可能,并如果可能,找到这样的一个适当的操作链。操作次数不应超过n+5。可以证明,如果存在这样的操作链,就存在一种方案最多进行n+5次操作。

**输入输出格式**

**输入格式**

每个测试包含多个测试用例。第一行包含一个整数t(1≤t≤10^5)——测试用例的数量。测试用例的描述如下。

每个测试用例的第一行包含一个整数n(2≤n≤2×10^5)——字符串的长度。

每个测试用例的第二行包含一个长度为n的二进制字符串a,只包含字符0和1。

每个测试用例的第三行包含一个长度为n的二进制字符串b,只包含字符0和1。

保证所有测试用例的n之和不超过2×10^5。

**输出格式**

对于每个测试用例,如果可能让两个字符串的所有元素都等于0,则首先输出"YES"。否则,输出"NO"。如果答案是"YES",则在下一行输出一个整数k(0≤k≤n+5)——操作的数量。然后是k行,每行包含两个整数l和r(1≤l≤r≤n)——操作的描述。

如果有多个正确答案,请输出其中任何一个。

**输入输出样例**

**输入样例 #1**

```
5
3
010
101
2
11
10
4
1000
0011
2
10
10
3
111
111
```

**输出样例 #1**

```
YES
1
2 2
NO
NO
YES
2
1 2
2 2
YES
2
1 1
2 3
```

**说明**

在第一个测试用例中,我们可以执行一个操作,l=2,r=2。所以a2:=1−1=0,字符串a变为000。b1:=1−1=0,b3:=1−1=0,字符串b变为000。

在第二个和第三个测试用例中,可以证明不可能让两个字符串的所有元素都等于0。

在第四个测试用例中,我们可以执行一个操作,l=1,r=2,然后字符串a变为01,字符串b不变。然后我们执行一个操作,l=2,r=2,a2:=1−1=0,b1=1−1=0。所以字符串a和b都变为00。

在第五个测试用例中,我们可以执行一个操作,l=1,r=1。然后字符串a变为011,字符串b变为100。然后我们可以执行一个操作,l=2,r=3,所以字符串a和b都变为000。**题意翻译** 你有两个01字符串a,b,长度均为n。你可以使用不超过n+5次下面这种操作: - 你选择两个下标l,r(1≤l≤r≤n)。 - 对于所有的i∈[l,r],取反ai(也就是说,ai→1−ai,下面同理)。 - 对于所有的i∈[1,l)∪(r,n],取反bi。 现在你的任务是判断是否可以通过使用不超过n+5次这种操作让两个串里的所有元素都变成0。如果可以,输出一种可能的方案。可以证明,如果使用任意次操作可以达成目标,那么至少存在一种方案可以在n+5次操作内达成目标。 n≥2,∑n≤2×10^5。 **题目描述** 你有两个二进制字符串a和b,长度为n。你想让这两个字符串的所有元素都等于0。不幸的是,你只能使用以下操作来修改这些字符串的内容: - 你选择两个索引l和r(1≤l≤r≤n); - 对于每个满足l≤i≤r的i,将ai更改为相反数。也就是说,ai:=1−ai; - 对于每个满足1≤i

加入题单

上一题 下一题 算法标签: