CF1466G.Song of the Sirens

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Whoso in ignorance draws near to them and hears the Sirens' voice, he nevermore returns.

Homer, Odyssey

In the times of Jason and the Argonauts, it was well known that sirens use the sound of their songs to lure sailors into their demise. Yet only a few knew that every time sirens call a sailor by his name, his will weakens, making him more vulnerable.

For the purpose of this problem, both siren songs and names of the sailors will be represented as strings of lowercase English letters. The more times the sailor's name occurs as a contiguous substring of the song, the greater danger he is in.

Jason found out that sirens can sing one of the n+1n+1 songs, which have the following structure: let sis_i (0≤i≤n0 \leq i \leq n) be the ii-th song and tt be a string of length nn, then for every i<ni \lt n: si+1=sitisis_{i+1} = s_i t_i s_i. In other words i+1i+1-st song is the concatenation of ii-th song, ii-th letter (00-indexed) of tt and the ii-th song.

Fortunately, he also knows s0s_0 and tt. Jason wonders how many times a sailor's name is mentioned in a particular song. Answer qq queries: given the sailor's name (ww) and the index of a song (ii) output the number of occurrences of ww in sis_i as a substring. As this number can be quite large, output its remainder modulo 109+710^9+7.

凡无知者趋近她们,听闻塞壬之歌声,便永无归途。

荷马,《奥德赛》

在伊阿宋与阿尔戈英雄们的时代,世人皆知塞壬以歌声引诱水手走向毁灭。然而,仅少数人知晓:每当塞壬呼唤水手之名,其意志便随之衰弱,从而更易受其蛊惑。

本题中,塞壬的歌声与水手的名字均以小写英文字母组成的字符串表示。水手之名作为歌声中连续子串出现的次数越多,其处境便越危险。

伊阿宋发现,塞壬可吟唱 n+1n+1 首歌曲之一,这些歌曲具有如下结构:设 sis_i(0≤i≤n0 \leq i \leq n)为第 ii 首歌曲,tt 为一个长度为 nn 的字符串,则对每个 i<ni < n,有 si+1=sitisis_{i+1} = s_i t_i s_i。换言之,第 i+1i+1 首歌曲由第 ii 首歌曲、字符串 tt 的第 ii 个字符(从 00 开始索引)以及第 ii 首歌曲拼接而成。

幸运的是,伊阿宋已知 s0s_0 与 tt。他想知道某位水手的名字在特定歌曲中被提及多少次。请回答 qq 个查询:给定水手的名字 ww 与歌曲编号 ii,输出 ww 在 sis_i 中作为子串出现的次数;由于该数值可能极大,请输出其对 109+710^9+7 取模的结果。

输入格式

In the first line of input there are two integers nn, qq ( $ 1 \leq n, q \leq 10^5$) meaning that there are n+1n+1 songs and qq queries. In the next two lines strings s0s_0 and tt follow (1≤∣s0∣≤100,∣t∣=n1 \leq |s_0| \leq 100, |t| = n).

Next qq lines describe the queries; each one contains an integer kk ($ 0 \leq k \leq n$), the index of the song sung by the sirens, and a non-empty string ww, which is the name of a sailor. All strings in this problem consist only of lowercase English letters, and the sum of lengths of sailors' names does not exceed 10610^6.

输入的第一行包含两个整数 nn、qq(1≤n,q≤1051 \leq n, q \leq 10^5),表示共有 n+1n+1 首歌曲和 qq 个查询。接下来两行分别为字符串 s0s_0 和 tt(1≤∣s0∣≤1001 \leq |s_0| \leq 100,∣t∣=n|t| = n)。

接下来的 qq 行描述各个查询;每行包含一个整数 kk(0≤k≤n0 \leq k \leq n),表示海妖所演唱的歌曲编号,以及一个非空字符串 ww,表示某位水手的名字。本题中所有字符串均由小写英文字母组成,且所有水手名字的长度总和不超过 10610^6。

输出格式

Output qq lines, ii-th of them should contain the remainder modulo 109+710^9+7 of the number of occurrences of ww in sks_k.

输出 qq 行,其中第 ii 行应包含子串 ww 在 sks_k 中出现次数对 109+710^9+7 取模的结果。

输入输出样例

  • 输入#1

    3 3
    aa
    bcd
    2 aba
    3 ca
    3 aa

    输出#1

    2
    2
    8
  • 输入#2

    4 5
    aba
    bbac
    1 a
    3 baca
    3 ab
    2 bab
    4 aba

    输出#2

    4
    0
    14
    6
    28

说明/提示

In the first example songs of the sirens are as follows:

  • Song 00: aa
  • Song 11: aabaa
  • Song 22: aabaacaabaa
  • Song 33: aabaacaabaadaabaacaabaa

在第一个例子中,塞壬的歌曲如下:

  • 歌曲 00: aa
  • 歌曲 11: aabaa
  • 歌曲 22: aabaacaabaa
  • 歌曲 33: aabaacaabaadaabaacaabaa

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

首页