CF1477B.Nezzar and Binary String

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Nezzar has a binary string ss of length nn that he wants to share with his best friend, Nanako. Nanako will spend qq days inspecting the binary string. At the same time, Nezzar wants to change the string ss into string ff during these qq days, because it looks better.

It is known that Nanako loves consistency so much. On the ii-th day, Nanako will inspect a segment of string ss from position lil_i to position rir_i inclusive. If the segment contains both characters '0' and '1', Nanako becomes unhappy and throws away the string.

After this inspection, at the ii-th night, Nezzar can secretly change strictly less than half of the characters in the segment from lil_i to rir_i inclusive, otherwise the change will be too obvious.

Now Nezzar wonders, if it is possible to avoid Nanako being unhappy and at the same time have the string become equal to the string ff at the end of these qq days and nights.

Nezzar 有一个长度为 nn 的二进制字符串 ss,他想将其分享给他的好朋友 Nanako。Nanako 将花费 qq 天时间来检查该二进制字符串。与此同时,Nezzar 希望在这 qq 天内将字符串 ss 变为字符串 ff,因为 ff 看起来更美观。

已知 Nanako 非常喜爱一致性。在第 ii 天,Nanako 将检查字符串 ss 中从位置 lil_i 到位置 rir_i(含端点)的子段。如果该子段中同时包含字符 '0' 和 '1',Nanako 就会不开心,并将该字符串丢弃。

在此检查之后,在第 ii 天晚上,Nezzar 可以秘密地修改该子段(即从 lil_i 到 rir_i,含端点)中严格少于一半的字符;否则,改动将过于明显。

现在 Nezzar 想知道:是否有可能既避免 Nanako 不开心,又使得经过这 qq 天及夜晚的操作后,字符串最终恰好变为字符串 ff?

输入格式

The first line contains a single integer tt (1≤t≤2⋅1051 \le t \le 2 \cdot 10^5) — the number of test cases.

The first line of each test case contains two integers n,qn,q (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5, 0≤q≤2⋅1050 \le q \le 2 \cdot 10^5).

The second line of each test case contains a binary string ss of length nn.

The third line of each test case contains a binary string ff of length nn.

Then qq lines follow, ii-th of them contains two integers li,ril_i,r_i (1≤li≤ri≤n1 \le l_i \le r_i \le n) — bounds of the segment, that Nanako will inspect on the ii-th day.

It is guaranteed that the sum of nn for all test cases doesn't exceed 2⋅1052 \cdot 10^5, and the sum of qq for all test cases doesn't exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤2⋅1051 \le t \le 2 \cdot 10^5)—— 测试用例的数量。

每个测试用例的第一行包含两个整数 n,qn,q(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5,0≤q≤2⋅1050 \le q \le 2 \cdot 10^5)。

每个测试用例的第二行包含一个长度为 nn 的二进制字符串 ss。

每个测试用例的第三行包含一个长度为 nn 的二进制字符串 ff。

接下来是 qq 行,其中第 ii 行包含两个整数 li,ril_i,r_i(1≤li≤ri≤n1 \le l_i \le r_i \le n)—— Nanako 在第 ii 天将检查的区间的左右边界。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5,且所有测试用例的 qq 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, print "YES" on the single line if it is possible to avoid Nanako being unhappy and have the string ff at the end of qq days and nights. Otherwise, print "NO".

You can print each letter in any case (upper or lower).

对于每个测试用例,如果能够在 qq 天 qq 夜后避免 Nanako 不开心,并使得字符串 ff 成为最终结果,则在单独一行输出 "YES";否则输出 "NO"。

你可以以任意大小写(大写或小写)输出每个字母。

输入输出样例

  • 输入#1

    4
    5 2
    00000
    00111
    1 5
    1 3
    2 1
    00
    01
    1 2
    10 6
    1111111111
    0110001110
    1 10
    5 9
    7 10
    1 7
    3 5
    6 10
    5 2
    10000
    11000
    2 5
    1 3

    输出#1

    YES
    NO
    YES
    NO

说明/提示

In the first test case, 00000‾→000‾11→00111\underline{00000} \rightarrow \underline{000}11 \rightarrow 00111 is one of the possible sequences of string changes.

In the second test case, it can be shown that it is impossible to have the string ff at the end.

在第一个测试用例中,00000‾→000‾11→00111\underline{00000} \rightarrow \underline{000}11 \rightarrow 00111 是字符串变化的一种可能序列。

在第二个测试用例中,可以证明最终无法得到字符串 ff。

输入解题思路,AI测评打分。不知道怎么写?

首页