题意:
对于26个字母 每个字母分别有一个权值
给出一个字符串,找出有多少个满足条件的子串,
条件:1、第一个字母和最后一个相同,2、除了第一个和最后一个字母外,其他的权和为0

思路:
预处理出sum[i]:s[0~i]的和
开26个map<LL, LL>numV 分别表示 每个字母前缀和 的个数
例如处理到第i个元素,且numV[s[i]-'a'][sum[i]-v[s[i] - 'a']] (值为2)
表示在处理到的元素之前 以s[i]结尾的前缀和为sum[i]-v[s[i]-'a']的个数有2个
所以答案就要加2(因为前面已经组成过这个值,又出现的原因就是他的值变为了0)

 const int maxv = ;
int v[maxv];
map<LL, LL> numV[maxv]; const int maxn = + ;
char s[maxn];
LL sum[maxn];
void init()
{
for (int i = ; i < ; i++)
{
scanf("%d", v + i);
}
scanf(" ");
gets(s);
} void solve()
{
int len = strlen(s);
sum[] = v[s[]-'a'];
for (int i = ; i < len; i++)
{
sum[i] = sum[i-] + v[s[i]-'a'];
} LL ans = ;
for (int i = ; i < len; i++)
{
ans += numV[s[i]-'a'][sum[i] - v[s[i] - 'a']];
numV[s[i]-'a'][sum[i]]++;
}
printf("%lld\n", ans);
} int main()
{
init();
solve();
return ;
}

Codeforces Round #294 (Div. 2) D. A and B and Interesting Substrings的更多相关文章

  1. Codeforces Round #294 (Div. 2)D - A and B and Interesting Substrings 字符串

    D. A and B and Interesting Substrings time limit per test 2 seconds memory limit per test 256 megaby ...

  2. Codeforces Round #294 (Div. 2) D. A and B and Interesting Substrings [dp 前缀和 ]

    传送门 D. A and B and Interesting Substrings time limit per test 2 seconds memory limit per test 256 me ...

  3. Codeforces Round #294 (Div. 2)

    水 A. A and B and Chess /* 水题 */ #include <cstdio> #include <algorithm> #include <iost ...

  4. Codeforces Round #294 (Div. 2)C - A and B and Team Training 水题

    C. A and B and Team Training time limit per test 1 second memory limit per test 256 megabytes input ...

  5. Codeforces Round #294 (Div. 2)B - A and B and Compilation Errors 水题

    B. A and B and Compilation Errors time limit per test 2 seconds memory limit per test 256 megabytes ...

  6. Codeforces Round #294 (Div. 2)A - A and B and Chess 水题

    A. A and B and Chess time limit per test 1 second memory limit per test 256 megabytes input standard ...

  7. Codeforces Round #294 (Div. 2) A and B and Lecture Rooms(LCA 倍增)

    A and B and Lecture Rooms time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  8. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  9. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

随机推荐

  1. sqlserver 存储过程分页管理

    -- =============================================-- Author:  <Author:刘畅>-- Create date: <Cre ...

  2. Extjs tree 更改图标

    去掉 树的叶子图标 .x-tree-node-icon { display: none; //不显示图标 } 更改图标  在后台返回的json中 有  添加  iconCls 属性 如    icon ...

  3. [DPDK][转]DPDK编程开发(4)—lcore

    1.知识百科 返回值 操作函数 函数功能 RTE_DECLARE_PER_LCORE (unsigned, _lcore_id) RTE_DECLARE_PER_LCORE (rte_cpuset_t ...

  4. VS2010默认属性文件配置

    问题: 在VS2010中,同一个解决方案下有多个项目,都需要使用某一个库. 如果项目比较多,或者编译链接环境属性变动频繁,分别对项目进行配置就很麻烦. 解决: 在VS的配置文件中统一配置属性: 我的配 ...

  5. Java在JFinal中出现Can not create instance of class: com.keesail.web.config.WebConfig异常处理方式

    编译的时候一直出现如下问题: 后面 查了许多资料 说是build项目的时候web.xml没有输出到class目录.后面试了很多方式不行.后面自己摸索出如下方式解决问题: 改成默认输出目录.

  6. mariadb配置允许远程访问方式

    首先配置允许访问的用户,采用授权的方式给用户权限 1 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '123456' WITH GRAN ...

  7. Log4j简介

    Log4J日志配置详解   一.Log4j简介Log4j有三个主要的组件:Loggers(记录器),Appenders (输出源)和Layouts(布局).这里可简单理解为日志类别,日志要输出的地方和 ...

  8. Question Of Rabbit

    题目描述 f(n) = GCD(1, n) + GCD(2, n) + GCD(3, n) + ~ ~ ~ + GCD(n - 1, n). 输入 每行一个整数N (1 < N < 400 ...

  9. uboot(二): Uboot-arm-start.s分析

    声明:该贴是通过参考其他人的帖子整理出来,从中我加深了对uboot的理解,我知道对其他人一定也是有很大的帮助,不敢私藏,如果里面的注释有什么错误请给我回复,我再加以修改.有些部分可能还没解释清楚,如果 ...

  10. 微软Face API体验——人脸检测

    微软推出了全新REST API,现在可免费获取密钥,大家可以赶快申请!申请地址:https://cn.projectoxford.ai/subscription 看了网站的API介绍,忍不住赶快体验一 ...