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的更多相关文章
随机推荐
- Microsoft Visual Studio 显示行号
工具下面有一个选项
- [CF1304E] 1-Trees and Queries - LCA
由于可以走重边,所以任意一条路径长 + 2 仍然对应至少一条合法路径 很显然我们有 \(3\) 种基本路径 不经过 \((x,y)\) 经过 \(x \to y\) 经过 \(y \to x\) 假设 ...
- Python模块/包/库安装几种方法(转载)
一.方法1: 单文件模块直接把文件拷贝到 $python_dir/Lib 二.方法2: 多文件模块,带setup.py 下载模块包(压缩文件zip或tar.gz),进行解压,CMD->cd进入模 ...
- 在 linux 中连接 mysql 数据库
命令格式 mysql -h主机地址 -u用户名 -p用户密码 登录本机 mysql mysql -u用户名 -p用户密码 实例 TD - X1数据库:/opt/lampp/bin/mysql -u r ...
- Mac升级后如何查看自己的网络端口
OS X 10.9 下面 网络实用工具 从实用工具目录里消失了,可能这个程序用的人太少就取消了吧.但是对于做互联网的人还是有点用的. 参考http://www.mamicode.com/info-de ...
- Zenject与UniRx结合实现跨线程通信Signal
修改Zenject下ProfileBlock.cs源码, 取消有关UnityEngine.Profiling.Profiler的代码. 然后使用Zenject的Signal: // 定义Signal ...
- js加密(二)文书获取
时间原因直接上代码,有空再解释. js代码: //var tm=new Array(1) //tm[0]=e; ////tm[1]="%u5e72%u82e5%u4f5c%u5de5%u88 ...
- C#处理不同的JSON数据
https://blog.csdn.net/dayu9216/article/details/78465681 网络中数据传输经常是xml或者json,现在做的一个项目之前调其他系统接口都是返回的xm ...
- C++-HDU1000,1001,1002-格式是真的坑
#include <cstdio> int main(){ for(int a,b;~scanf("%d%d",&a,&b);printf(" ...
- c++中sort函数调用报错Expression : invalid operator <的内部原理 及解决办法
转自:https://www.cnblogs.com/huoyao/p/4248925.html 当我们调用sort函数进行排序时,中的比较函数如果写成如下 bool cmp(const int &a ...