306929: CF1272C. Yet Another Broken Keyboard

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Yet Another Broken Keyboard

题意翻译

## 题目描述 $Norge$,找到了一个长度为$n$的字符串$s$($s$仅由小写英文字母构成),他想把这个字符串的所有$\frac{n(n+1)}{2}$个连续非空子串都打出来 可是,他发现他的键盘坏了,只能打出26字母中的$k$个 这$k$个字母分别为:$c_1,c_2,c_3,\dots ,c_k$ 请求出用这个坏掉的键盘,最多能打出多少个字符串$s$的连续非空子串 ## 输入格式 第一行两个整数 $n,k$ ,表示字符串$s$的长度,和能用字母的数量 第二行一个长度为$n$字符串$s$ 第三行,$k$个由空格隔开的字母,表示键盘上没有坏掉的字母 ## 输出格式 一行一个整数,表示用这个坏掉的键盘,最多能打出多少个字符串$s$的连续非空子串 ### 数据范围 $1\leq n \le 2\cdot 10^5$,$1\leq k \le 26$ 感谢 @_Wolverine 提供的翻译

题目描述

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.

输入输出格式

输入格式


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.

输出格式


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] $ .

Input

题意翻译

## 题目描述 $Norge$,找到了一个长度为$n$的字符串$s$($s$仅由小写英文字母构成),他想把这个字符串的所有$\frac{n(n+1)}{2}$个连续非空子串都打出来 可是,他发现他的键盘坏了,只能打出26字母中的$k$个 这$k$个字母分别为:$c_1,c_2,c_3,\dots ,c_k$ 请求出用这个坏掉的键盘,最多能打出多少个字符串$s$的连续非空子串 ## 输入格式 第一行两个整数 $n,k$ ,表示字符串$s$的长度,和能用字母的数量 第二行一个长度为$n$字符串$s$ 第三行,$k$个由空格隔开的字母,表示键盘上没有坏掉的字母 ## 输出格式 一行一个整数,表示用这个坏掉的键盘,最多能打出多少个字符串$s$的连续非空子串 ### 数据范围 $1\leq n \le 2\cdot 10^5$,$1\leq k \le 26$ 感谢 @_Wolverine 提供的翻译

加入题单

算法标签: