CF1320D.Reachable Strings
省选/NOI-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 s starting from the l-th character and ending with the r-th character as s[l…r]. The characters of each string are numbered from 1.
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 a is considered reachable from binary string b if there exists a sequence s1, s2, ..., sk such that s1=a, sk=b, and for every i∈[1,k−1], si can be transformed into si+1 using exactly one operation. Note that k can be equal to 1, i. e., every string is reachable from itself.
You are given a string t and q queries to it. Each query consists of three integers l1, l2 and len. To answer each query, you have to determine whether t[l1…l1+len−1] is reachable from t[l2…l2+len−1].
本题中,我们将处理二进制字符串。二进制字符串的每个字符均为 0 或 1。我们还会涉及子串(substring)的概念;回忆一下,子串是字符串的一个连续子序列。我们用 s[l…r] 表示字符串 s 中从第 l 个字符开始、到第 r 个字符结束的子串。每个字符串的字符编号从 1 开始。
我们可以对所考虑的字符串执行若干操作。每次操作是选择字符串的一个子串,并将其替换为另一个字符串。操作共有两种类型:将 011 替换为 110,或将 110 替换为 011。例如,若对字符串 110011110 恰好执行一次操作,则它可以被变换为 011011110、110110110 或 110011011。
若存在一个序列 s1,s2,…,sk,使得 s1=a、sk=b,且对每个 i∈[1,k−1],si 均可通过恰好一次操作变换为 si+1,则称二进制字符串 a 是从二进制字符串 b 可达的(reachable)。注意,k 可以等于 1,即每个字符串均从其自身可达。
给定一个字符串 t 和 q 个关于它的查询。每个查询包含三个整数 l1、l2 和 len。对于每个查询,你需要判断子串 t[l1…l1+len−1] 是否可从子串 t[l2…l2+len−1] 到达。
输入格式
The first line contains one integer n (1≤n≤2⋅105) — the length of string t.
The second line contains one string t (∣t∣=n). Each character of t is either 0 or 1.
The third line contains one integer q (1≤q≤2⋅105) — the number of queries.
Then q lines follow, each line represents a query. The i-th line contains three integers l1, l2 and len (1≤l1,l2≤∣t∣, 1≤len≤∣t∣−max(l1,l2)+1) for the i-th query.
第一行包含一个整数 n(1≤n≤2⋅105)—— 字符串 t 的长度。
第二行包含一个字符串 t(∣t∣=n)。t 的每个字符均为 0 或 1。
第三行包含一个整数 q(1≤q≤2⋅105)—— 查询的个数。
接下来有 q 行,每行表示一个查询。第 i 行包含三个整数 l1、l2 和 len(1≤l1,l2≤∣t∣,1≤len≤∣t∣−max(l1,l2)+1),对应第 i 个查询。
输出格式
For each query, print either YES if t[l1…l1+len−1] is reachable from t[l2…l2+len−1], or NO otherwise. You may print each letter in any register.
对于每个查询,如果 t[l1…l1+len−1] 可从 t[l2…l2+len−1] 到达,则输出 YES;否则输出 NO。每个字母可使用任意大小写形式输出。
输入输出样例
输入#1
5 11011 3 1 3 3 1 4 2 1 2 3
输出#1
Yes Yes No
输入解题思路,AI测评打分。不知道怎么写?