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的更多相关文章
随机推荐
- numpy学习(一)
(一)基础学习 学习渠道:阿里天池AI学习——Numpy基础(传送门) (二)练习篇 练习渠道:Numpy基础100题(Part 1) 1. Import the numpy package unde ...
- centos7搭建天兔
如果新系统尚未安装工具pip,可通过以下三步快速安装pip 1. yum -y install epel-release 2. yum -y ...
- bootstrap之表格自适应 table-responsive
<div class=table-responsive"> <table class="table"> <thead> <tr& ...
- 重载(Overload)和重写(Override)的区别是什么?
首先java程序的运行分为编译和运行两部分. 所以重载和重写在这一点就有很明显的区别,因为重写方法的方法名和参数个数类型都一样,所以在java虚拟机的编译阶段是识别不出重写的方法的不同,在运行期间才可 ...
- leetcode腾讯精选练习之相交链表(六)
相交链表 题目: 编写一个程序,找到两个单链表相交的起始节点. 如下面的两个链表: 在节点 c1 开始相交. 示例 1: 输入:intersectVal = 8, listA = [4,1,8,4,5 ...
- 2.4测试赛AC代码临时保存
//H #include<cstdio> #include<cstdlib> #include<cstring> #include<stack> usi ...
- Carmichael Numbers (快速幂)
当今计算机科学的一个重要的领域就是密码学.有些人甚至认为密码学是计算机科学中唯一重要的领域,没有密码学生命都没有意义. 阿尔瓦罗就是这样的一个人,它正在设计一个为西班牙杂烩菜饭加密的步骤.他在加 ...
- C正数负数的原码补码反码以及内存地址分析
#include<stdio.h> void swap(int a, int b); void main1(){ int i = 10; //正数的原码 00000000 00000000 ...
- 大数据-HBase
HBase HBase(Hadoop Database)基于Google的BigTable论文,依赖HDFS进行存储.适合存储大体量数据.HBase是高可靠性(数据安全).高性能(存取效率).面向列. ...
- java的jdk和jre区别
本文是本人随便总结的== 首先大概清楚个关系:jdk 包含 jre 包含 jvm 然后来看下,当我们配置完java运行环境的时候,是不是在java默认安装文件下发现jdk和jre两个包,然后jdk包里 ...