CF1721E.Prefix Function Queries

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a string ss, consisting of lowercase Latin letters.

You are asked qq queries about it: given another string tt, consisting of lowercase Latin letters, perform the following steps:

  1. concatenate ss and tt;
  2. calculate the prefix function of the resulting string s+ts+t;
  3. print the values of the prefix function on positions ∣s∣+1,∣s∣+2,…,∣s∣+∣t∣|s|+1, |s|+2, \dots, |s|+|t| (∣s∣|s| and ∣t∣|t| denote the lengths of strings ss and tt, respectively);
  4. revert the string back to ss.

The prefix function of a string aa is a sequence p1,p2,…,p∣a∣p_1, p_2, \dots, p_{|a|}, where pip_i is the maximum value of kk such that k<ik \lt i and a[1..k]=a[i−k+1..i]a[1..k]=a[i-k+1..i] (a[l..r]a[l..r] denotes a contiguous substring of a string aa from a position ll to a position rr, inclusive). In other words, it's the longest proper prefix of the string a[1..i]a[1..i] that is equal to its suffix of the same length.

给你一个由小写拉丁字母组成的字符串 ss。

你需要处理 qq 个关于该字符串的查询:对于每个查询,给定另一个由小写拉丁字母组成的字符串 tt,执行以下步骤:

  1. 将 ss 和 tt 拼接起来;
  2. 计算拼接后字符串 s+ts+t 的前缀函数;
  3. 输出前缀函数在位置 ∣s∣+1,∣s∣+2,…,∣s∣+∣t∣|s|+1, |s|+2, \dots, |s|+|t| 上的值(其中 ∣s∣|s| 和 ∣t∣|t| 分别表示字符串 ss 和 tt 的长度);
  4. 将字符串恢复为 ss。

字符串 aa 的前缀函数是一个序列 p1,p2,…,p∣a∣p_1, p_2, \dots, p_{|a|},其中 pip_i 是满足 k<ik \lt i 且 a[1..k]=a[i−k+1..i]a[1..k]=a[i-k+1..i] 的最大 kk 值(a[l..r]a[l..r] 表示字符串 aa 中从位置 ll 到位置 rr(含端点)的连续子串)。换言之,pip_i 是字符串 a[1..i]a[1..i] 的最长真前缀,该前缀同时等于其长度相同的后缀。

输入格式

The first line contains a non-empty string ss (1≤∣s∣≤1061 \le |s| \le 10^6), consisting of lowercase Latin letters.

The second line contains a single integer qq (1≤q≤1051 \le q \le 10^5) — the number of queries.

Each of the next qq lines contains a query: a non-empty string tt (1≤∣t∣≤101 \le |t| \le 10), consisting of lowercase Latin letters.

第一行包含一个非空字符串 ss(1≤∣s∣≤1061 \le |s| \le 10^6),由小写拉丁字母组成。

第二行包含一个整数 qq(1≤q≤1051 \le q \le 10^5)—— 查询次数。

接下来的 qq 行,每行包含一个查询:一个非空字符串 tt(1≤∣t∣≤101 \le |t| \le 10),由小写拉丁字母组成。

输出格式

For each query, print the values of the prefix function of a string s+ts+t on positions ∣s∣+1,∣s∣+2,…,∣s∣+∣t∣|s|+1, |s|+2, \dots, |s|+|t|.

对于每个查询,输出字符串 s+ts+t 在位置 ∣s∣+1,∣s∣+2,…,∣s∣+∣t∣|s|+1, |s|+2, \dots, |s|+|t| 处的前缀函数值。

输入输出样例

  • 输入#1

    aba
    6
    caba
    aba
    bababa
    aaaa
    b
    forces

    输出#1

    0 1 2 3 
    1 2 3 
    2 3 4 5 6 7 
    1 1 1 1 
    2 
    0 0 0 0 0 0
  • 输入#2

    aacba
    4
    aaca
    cbbb
    aab
    ccaca

    输出#2

    2 2 3 1 
    0 0 0 0 
    2 2 0 
    0 0 1 0 1

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

首页