• Welcome to the world's largest Chinese hacker forum

    Welcome to the world's largest Chinese hacker forum, our forum registration is open! You can now register for technical communication with us, this is a free and open to the world of the BBS, we founded the purpose for the study of network security, please don't release business of black/grey, or on the BBS posts, to seek help hacker if violations, we will permanently frozen your IP and account, thank you for your cooperation. Hacker attack and defense cracking or network Security

    business please click here: Creation Security  From CNHACKTEAM

Recommended Posts

6050. 字符串的总引力

对于任何子串,观察序列中每个字符对子串“引力”的贡献。我们规定序列中第一个字符贡献1,其他字符贡献0。

遍历字符串S,统计每个字符的贡献,也就是每个字符可以贡献的子字符串的个数。

保持当前遍历字符的最后出现位置h。

那么左端点在\([H 1,i]\)右端点在\([i,n]\)的子串都可以贡献1。

所以每次\(RES=(I-H)*(n-I 1)\);

类别解决方案{

公共:

long long appears sum(string s){

使用ll=long long

ll n=s.size(),RES=0;

s=s;

unordered_mapint,intH

for(ll I=1;I=n;i) {

RES=(I-H[s-a '])*(n-I 1);//统计数据

h[s-' a ']=I;//更新h

}

返回res

}

};

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now