CF923D.Picking Strings

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Alice has a string consisting of characters 'A', 'B' and 'C'. Bob can use the following transitions on any substring of our string in any order any number of times:

  • A BC
  • B AC
  • C AB
  • AAA empty string

Note that a substring is one or more consecutive characters. For given queries, determine whether it is possible to obtain the target string from source.

Alice 有一个由字符 'A'、'B' 和 'C' 组成的字符串。Bob 可以对字符串中任意子串(即一个或多个连续字符)以任意顺序、任意次数执行以下变换:

  • A BC
  • B AC
  • C AB
  • AAA 空字符串

注意:子串是指一个或多个连续的字符。对于给定的若干查询,判断是否能从源字符串得到目标字符串。

输入格式

The first line contains a string S (1 ≤ |S| ≤ 105). The second line contains a string T (1 ≤ |T| ≤ 105), each of these strings consists only of uppercase English letters 'A', 'B' and 'C'.

The third line contains the number of queries Q (1 ≤ Q ≤ 105).

The following Q lines describe queries. The i-th of these lines contains four space separated integers a__i, b__i, c__i, d__i. These represent the i-th query: is it possible to create T[c__i..d__i] from S[a__i..b__i] by applying the above transitions finite amount of times?

Here, U[x..y] is a substring of U that begins at index x (indexed from 1) and ends at index y. In particular, U[1..|U|] is the whole string U.

It is guaranteed that 1 ≤ a ≤ b ≤ |S| and 1 ≤ c ≤ d ≤ |T|.

第一行包含一个字符串 SS(1≤∣S∣≤1051 \leq |S| \leq 10^5)。第二行包含一个字符串 TT(1≤∣T∣≤1051 \leq |T| \leq 10^5),这两个字符串均由大写英文字母 'A'、'B' 和 'C' 组成。

第三行包含查询数量 QQ(1≤Q≤1051 \leq Q \leq 10^5)。

接下来的 QQ 行描述各个查询。其中第 ii 行包含四个以空格分隔的整数 aia_i、bib_i、cic_i、did_i,表示第 ii 个查询:能否通过对 S[ai..bi]S[a_i..b_i] 有限次应用上述变换,得到 T[ci..di]T[c_i..d_i]?

此处,U[x..y]U[x..y] 表示字符串 UU 中从下标 xx(下标从 1 开始)开始、到下标 yy 结束的子串。特别地,U[1..∣U∣]U[1..|U|] 即为整个字符串 UU。

保证满足 1≤a≤b≤∣S∣1 \leq a \leq b \leq |S| 且 1≤c≤d≤∣T∣1 \leq c \leq d \leq |T|。

输出格式

Print a string of Q characters, where the i-th character is '1' if the answer to the i-th query is positive, and '0' otherwise.

输出一个长度为 QQ 的字符串,其中第 ii 个字符为 '1' 当且仅当第 ii 个查询的答案为正,否则为 '0'。

输入输出样例

  • 输入#1

    AABCCBAAB
    ABCB
    5
    1 3 1 2
    2 2 2 4
    7 9 1 1
    3 4 2 3
    4 5 1 3

    输出#1

    10011

说明/提示

In the first query we can achieve the result, for instance, by using transitions .

The third query asks for changing AAB to A — but in this case we are not able to get rid of the character 'B'.

在第一次查询中,我们可以通过使用如下转移来实现结果:。

第三次查询要求将 AAB 变为 A — 但在这种情况下,我们无法消除字符 'B'。

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

首页