题意 给出$26$个字母对应的权值和一个字符串 问满足以下条件的子串有多少 首尾字母相同 中间字母权值相加为0 Sol 我们要找到区间满足$sum[i] - sum[j] = 0$ $sum[i] = sum[j]$ 开$26$个map维护一下$sum$相等的子串就可以 /* */ #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<map…
题意: 已知26个小写字母有各自的权值(正,负,或0) 现在给出一个字符串,长度<=1e5 问这个字符串有多少个子串满足: 开头的字母和结尾的字母一样 字符串除了开头和结尾的字母外,其余的字母的权值和为0 本来是一道水题,一看就知道大体的思路了,结果硬是搞了一个多小时 先是用set,发现超时了,改为用map 思路: 1.我们先预处理这个字符串的权值的前缀和 sum[i]表示从字符串的起点到i的权值和 2.我们要找到的子串,设以l开头和r结尾,则有 str[r] == str[l] 和 sum[r…
传送门 D. A and B and Interesting Substrings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A and B are preparing themselves for programming contests. After several years of doing sports pro…
题目链接:D. A and B and Interesting Substrings 题目大意 给定26个小写字母的权值,一共26个整数(有正有负). 给定一个小写字母组成的字符串(长度10^5),求有多少长度大于1的子串满足: 1)首尾字符相同. 2)除了首尾字符外,其他字符的权值和为0. 题目分析 使用STL Map.开26个Map,给每个字母开一个. 先求出权值的前缀和 Sum[] . 然后1到l枚举每一位字符,如果是a,那么 Ans += Map[a][Sum[i - 1]]; 然后 +…
A:http://codeforces.com/problemset/problem/519/A 水题没什么好说的. #include <iostream> #include <string.h> #include <stdio.h> #include <math.h> #include <algorithm> #include <queue> #define inf 0x3f3f3f3f using namespace std; ]…
D. A and B and Interesting Substrings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A and B are preparing themselves for programming contests. After several years of doing sports program…
题目链接:http://codeforces.com/problemset/problem/519/D 题目大意:给你一串字符串s仅由小写字母组成,并且对于'a'~'z'都给了一个值.求子串t满足t的开头和结尾字符相同,且中间的字符的值相加为0,求子串t的数目.解题思路:设置map<LL,int>mp[26]这样的二维map,记录对应以每个字母结尾的前缀和的值的出现次数.然后计算前缀和sum,每次计算sum+val[s[i]]前,先计算ans,因为sum[i-1]-sum[x]==0才能说明s…
题意: 对于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']的个…
题意:相邻的两端回文串的价值为两个回文串总的区间左端点 × 区间右端点.然后计算目标串中所有该情况的总和. 思路:首先用manacher求出所有中心点的最大半径,然后我们知道对于左区间我们把贡献记录在右端点,右区间记录在左端点.然后细节的我就不太懂了.迷~ #include<bits/stdc++.h> using namespace std; ; ; long long rad[maxn], L[maxn], R[maxn], cnt1[maxn], cnt2[maxn]; char in[…
题意:给出26个字母每个字母的价值,问字符串中有多少个满足以下条件的子串: 1.子串的第一个和最后一个相同 2.子串除了头和尾的其他字符的价值加起来和尾0 这题普通方法应该是O(n^2),但是在1e5的条件下肯定会超时,所以学习了大力学长奥义的O(n)方法.具体方法也说不清楚,看代码吧,很短,也容易看懂.只能说,相当奥义的方法.. 代码如下: #include <stdio.h> #include <algorithm> #include <string.h> #inc…