#P1320D. Reachable Strings
Reachable Strings
No submission language available for this problem.
Description
In this problem, we will deal with binary strings. Each character of a binary string is either a 0 or a 1. We will also deal with substrings; recall that a substring is a contiguous subsequence of a string. We denote the substring of string starting from the -th character and ending with the -th character as . The characters of each string are numbered from .
We can perform several operations on the strings we consider. Each operation is to choose a substring of our string and replace it with another string. There are two possible types of operations: replace 011 with 110, or replace 110 with 011. For example, if we apply exactly one operation to the string 110011110, it can be transformed into 011011110, 110110110, or 110011011.
Binary string is considered reachable from binary string if there exists a sequence , , ..., such that , , and for every , can be transformed into using exactly one operation. Note that can be equal to , i. e., every string is reachable from itself.
You are given a string and queries to it. Each query consists of three integers , and . To answer each query, you have to determine whether is reachable from .
The first line contains one integer () — the length of string .
The second line contains one string (). Each character of is either 0 or 1.
The third line contains one integer () — the number of queries.
Then lines follow, each line represents a query. The -th line contains three integers , and (, ) for the -th query.
For each query, print either YES if is reachable from , or NO otherwise. You may print each letter in any register.
Input
The first line contains one integer () — the length of string .
The second line contains one string (). Each character of is either 0 or 1.
The third line contains one integer () — the number of queries.
Then lines follow, each line represents a query. The -th line contains three integers , and (, ) for the -th query.
Output
For each query, print either YES if is reachable from , or NO otherwise. You may print each letter in any register.