CF1272C
Recently, Norge found a string s=s1s2…sns=s1s2…sn consisting of nn lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string ss. Yes, all n(n+1)2n(n+1)2 of them!
A substring of ss is a non-empty string x=s[a…b]=sasa+1…sbx=s[a…b]=sasa+1…sb (1≤a≤b≤n1≤a≤b≤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 kk Latin letters c1,c2,…,ckc1,c2,…,ck out of 2626.
After that, Norge became interested in how many substrings of the string ss he could still type using his broken keyboard. Help him to find this number.
The first line contains two space-separated integers nn and kk (1≤n≤2⋅1051≤n≤2⋅105, 1≤k≤261≤k≤26) — the length of the string ss and the number of Latin letters still available on the keyboard.
The second line contains the string ss consisting of exactly nn lowercase Latin letters.
The third line contains kk space-separated distinct lowercase Latin letters c1,c2,…,ckc1,c2,…,ck — the letters still available on the keyboard.
Print a single number — the number of substrings of ss that can be typed using only available letters c1,c2,…,ckc1,c2,…,ck.
7 2
abacaba
a b
12
10 3
sadfaasdda
f a d
21
7 1
aaaaaaa
b
0
In the first example Norge can print substrings s[1…2]s[1…2], s[2…3]s[2…3], s[1…3]s[1…3], s[1…1]s[1…1], s[2…2]s[2…2], s[3…3]s[3…3], s[5…6]s[5…6], s[6…7]s[6…7], s[5…7]s[5…7], s[5…5]s[5…5], s[6…6]s[6…6], s[7…7]s[7…7].
题倒是简单但是s=200000这样的数据用int就中招了
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <cmath>
#define LL long long
using namespace std; int main()
{
int n, k;
cin >> n >> k;
string s;
cin >> s;
set<char> all;
for (int i = ; i < k; i++)
{
char t;
cin >> t;
all.insert(t);
}
LL cnt=,sum=;
for (int i = ; i < s.size(); i++)
{
if (all.find(s[i]) != all.end())
{
cnt++;
}
else
{
sum += cnt*(cnt + ) / ;
cnt = ;
}
if(i==s.size()- && all.find(s[i]) != all.end())
sum += cnt*(cnt + ) / ;
}
cout << sum;
//system("pause");
return ;
}
CF1272C的更多相关文章
随机推荐
- 机器学习作业(三)多类别分类与神经网络——Matlab实现
题目太长了!下载地址[传送门] 第1题 简述:识别图片上的数字. 第1步:读取数据文件: %% Setup the parameters you will use for this part of t ...
- 158.Clickjacking点击劫持攻击实现和防御措施
clickjacking攻击: clickjacking攻击又称为点击劫持攻击,是一种在网页中将恶意代码等隐藏在看似无害的内容(如按钮)之下,并诱使用户点击的手段. clickjacking攻击场景: ...
- javaScript(Date与Math的API)
目录 Math Math的两个属性值 E PI abs(); ceil(); floor(); round(); max(); min (); pow(); random sin(); cos(); ...
- 检测识别问题中的metrics
之前一直记不熟各种指标的具体计算,本文准备彻底搞定这个问题,涵盖目前遇到过的所有评价指标. TP,TN,FP,FN 首先是true-false和positive-negative这两对词.以二分类为例 ...
- Copy Paste DWG to older 3ds Max
Hi, This is quick tutorial: how to install Auto Cad scripts to be able to copy from newer Auto Cad t ...
- 【HTML】iframe嵌套界面自适应,可高度自由收缩
最近在做网页时需要使iframe高度自适应,以提高用户体验,网上找了挺多都很复杂,最后找到了这个 HTML: <div class="main_page"> <i ...
- 用html5自带表单验证 并且用ajax提交的解决方法(附例子)
用submit来提交表单,然后在js中监听submit方法,用ajax提交表单最后阻止submit的自动提交. 在标准浏览器中,阻止浏览器默认行为使用event.preventDefault(),而在 ...
- U盘拷贝目标文件过大无法复制时的解决方法
在cmd下输入:convert U盘符:/fs:ntfs ---> 回车 转换完成后可以看到U盘属性为NTFS了 这时就可以复制大文件到U盘了
- 【转载】Hibernate映射文件详解
转自:http://blog.163.com/hzd_love/blog/static/13199988120108265317988/ Hibernate的持久化类和关系数据库之间的映射通常是用一个 ...
- script放在body和放在head的区别
放在body中:在页面加载的时候被执行 放在head中:在被调用时被执行 原因: 1.浏览器是从上到下解析HTML的. 2.放在head里的js代码,会在body解析之前被解析:放在body里的js代 ...