A13125 | Yet Another Broken Keyboard
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Recently, Norge found a string $s = s_1 s_2 \ldots s_n$ consisting of $n$ lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string $s$ . Yes, all $\frac{n (n + 1)}{2}$ of them!
A substring of $s$ is a non-empty string $x = s[a \ldots b] = s_{a} s_{a + 1} \ldots s_{b}$ ( $1 \leq a \leq b \leq n$ ). For example, "auto" and "ton" are substrings of "automaton".
Shortly after the start of the exercise, Norge realized that his keyboard was broken, namely, he could use only $k$ Latin letters $c_1, c_2, \ldots, c_k$ out of $26$ .
After that, Norge became interested in how many substrings of the string $s$ he could still type using his broken keyboard. Help him to find this number.
A substring of $s$ is a non-empty string $x = s[a \ldots b] = s_{a} s_{a + 1} \ldots s_{b}$ ( $1 \leq a \leq b \leq n$ ). For example, "auto" and "ton" are substrings of "automaton".
Shortly after the start of the exercise, Norge realized that his keyboard was broken, namely, he could use only $k$ Latin letters $c_1, c_2, \ldots, c_k$ out of $26$ .
After that, Norge became interested in how many substrings of the string $s$ he could still type using his broken keyboard. Help him to find this number.
输入格式
The first line contains two space-separated integers $n$ and $k$ ( $1 \leq n \leq 2 \cdot 10^5$ , $1 \leq k \leq 26$ ) — the length of the string $s$ and the number of Latin letters still available on the keyboard.
The second line contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
The third line contains $k$ space-separated distinct lowercase Latin letters $c_1, c_2, \ldots, c_k$ — the letters still available on the keyboard.
The second line contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
The third line contains $k$ space-separated distinct lowercase Latin letters $c_1, c_2, \ldots, c_k$ — the letters still available on the keyboard.
输出格式
Print a single number — the number of substrings of $s$ that can be typed using only available letters $c_1, c_2, \ldots, c_k$ .
输入输出样例
输入 #1
7 2 abacaba a b
输出 #1
12
输入 #2
10 3 sadfaasdda f a d
输出 #2
21
输入 #3
7 1 aaaaaaa b
输出 #3
0
In the first example Norge can print substrings $s[1\ldots2]$ , $s[2\ldots3]$ , $s[1\ldots3]$ , $s[1\ldots1]$ , $s[2\ldots2]$ , $s[3\ldots3]$ , $s[5\ldots6]$ , $s[6\ldots7]$ , $s[5\ldots7]$ , $s[5\ldots5]$ , $s[6\ldots6]$ , $s[7\ldots7]$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted