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的更多相关文章
随机推荐
- lampp ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'lepus'
解决方法: 在[mysqlld]段下增加如下代码:skip-grant-tables: 1.which mysql 查看mysql位置,例如:/opt/lampp/bin/mysql 2.进入配置my ...
- Wannafly Camp 2020 Day 3A 黑色气球
#include <bits/stdc++.h> using namespace std; int a[1005][1005],n,x[1005]; int main() { scanf( ...
- (转)java中新生代和老年代
转自:http://blog.csdn.net/lojze_ly/article/details/49456255 聊聊JVM的年轻代 1.为什么会有年轻代 我们先来屡屡,为什么需要把堆分代?不分代不 ...
- Oracle 中的 Incarnation 到底是个什么?实验操作篇
对于“化身”Incarnation概念了解之后,本篇通过手工恢复实验来具体操作演示,加深对Incarnation的理解,来自于博客园AskScuti. 你可以点击此处查看<概念理解篇>. ...
- soundtouch change rate matlab implementation
soundtouch implement of changing rate in a way same with resample(SRC). When rate < 1, it need in ...
- 用html5自带表单验证 并且用ajax提交的解决方法(附例子)
用submit来提交表单,然后在js中监听submit方法,用ajax提交表单最后阻止submit的自动提交. 在标准浏览器中,阻止浏览器默认行为使用event.preventDefault(),而在 ...
- Oracle用户权限授权以及索引、同义词、分区
本文为原创,如需转载,请标明出处 http://www.cnblogs.com/gudu1/p/7601765.html ---- 用户权限 1.创建表空间 (创建用户之前需要创建表空间和临时表空间, ...
- 解决windows配置visual studio code调试golang环境问题
写这篇随笔是为了Mark下在这个过程中配到的几个问题 1.具体过程可参考https://www.cnblogs.com/JerryNo1/p/5412864.html,Jerry博主写的非常详细了 1 ...
- 圆桌问题 (ArrayList+模拟)
圆桌上围坐着2n个人.其中n个人是好人,另外n个人是坏人.如果从第一个人开始数数,数到第m个人,则立即处死该人:然后从被处死的人之后开始数数,再将数到的第m个人处死……依此方法不断处死围坐在圆桌上的人 ...
- 2.Map中hashMap和hashTable两个的对比
我们来对比一下hashMap和hashTable吧: 1.hashMap允许键.值可以为空,hashTable键和值都不可以为空,为什么这样呢,我们来看一下他们的put方法的源码. 先看hashMap ...