A14044 | Song of the Sirens
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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+1$ songs, which have the following structure: let $s_i$ ( $0 \leq i \leq n$ ) be the $i$ -th song and $t$ be a string of length $n$ , then for every $i < n$ : $s_{i+1} = s_i t_i s_i$ . In other words $i+1$ -st song is the concatenation of $i$ -th song, $i$ -th letter ( $0$ -indexed) of $t$ and the $i$ -th song.
Fortunately, he also knows $s_0$ and $t$ . Jason wonders how many times a sailor's name is mentioned in a particular song. Answer $q$ queries: given the sailor's name ( $w$ ) and the index of a song ( $i$ ) output the number of occurrences of $w$ in $s_i$ as a substring. As this number can be quite large, output its remainder modulo $10^9+7$ .
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+1$ songs, which have the following structure: let $s_i$ ( $0 \leq i \leq n$ ) be the $i$ -th song and $t$ be a string of length $n$ , then for every $i < n$ : $s_{i+1} = s_i t_i s_i$ . In other words $i+1$ -st song is the concatenation of $i$ -th song, $i$ -th letter ( $0$ -indexed) of $t$ and the $i$ -th song.
Fortunately, he also knows $s_0$ and $t$ . Jason wonders how many times a sailor's name is mentioned in a particular song. Answer $q$ queries: given the sailor's name ( $w$ ) and the index of a song ( $i$ ) output the number of occurrences of $w$ in $s_i$ as a substring. As this number can be quite large, output its remainder modulo $10^9+7$ .
输入格式
In the first line of input there are two integers $n$ , $q$ ( $ 1 \leq n, q \leq 10^5$ ) meaning that there are $n+1$ songs and $q$ queries. In the next two lines strings $s_0$ and $t$ follow ( $1 \leq |s_0| \leq 100, |t| = n$ ).
Next $q$ lines describe the queries; each one contains an integer $k$ ( $ 0 \leq k \leq n$ ), the index of the song sung by the sirens, and a non-empty string $w$ , 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 $10^6$ .
Next $q$ lines describe the queries; each one contains an integer $k$ ( $ 0 \leq k \leq n$ ), the index of the song sung by the sirens, and a non-empty string $w$ , 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 $10^6$ .
输出格式
Output $q$ lines, $i$ -th of them should contain the remainder modulo $10^9+7$ of the number of occurrences of $w$ in $s_k$ .
输入输出样例
输入 #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 $0$ : aa
- Song $1$ : aabaa
- Song $2$ : aabaacaabaa
- Song $3$ : aabaacaabaadaabaacaabaa
- Song $0$ : aa
- Song $1$ : aabaa
- Song $2$ : aabaacaabaa
- Song $3$ : aabaacaabaadaabaacaabaa
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted