D. Picking Strings

Codeforces
IDCF947D
Time2000ms
Memory256MB
Difficulty
constructive algorithmsimplementationstrings
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. ## Input 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_|. ## Output 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. [samples] ## Note 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_'.
Samples
Input #1
AABCCBAAB
ABCB
5
1 3 1 2
2 2 2 4
7 9 1 1
3 4 2 3
4 5 1 3
Output #1
10011
API Response (JSON)
{
  "problem": {
    "name": "D. Picking Strings",
    "description": {
      "content": "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_ * ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF947D"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "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:\n\n*   _A_ _BC_\n*   _B_ _AC_\n* ...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments