Yet Another Broken Keyboard[双指针]

题目大意:

求贡献,已知公式n*(n+1)/2,求总和

收获:

long long的转换技巧只能在乘或除上进行

题目链接

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N=2e5+10;


int main()
{
    int n,k;cin>>n>>k;
    set<char>st;string s,s1;
    cin>>s;
    char tmp;
    for(int i=0;i<k;++i) cin>>tmp,st.insert(tmp);
    ll ans=0;
    for(int i=0;i<s.size();++i){
        int j=i;
        while(j<s.size()&&st.count(s[j])) ++j;
        ans+=1ll*(j-i)*(j-i+1)/2;
        i=j;
    }
    cout<<ans<<endl;
    return 0;
}
原文地址:https://www.cnblogs.com/waryan/p/12286864.html