fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4. ll n,m,a[500005],b[500050],mn,q,ans,r,l,c,sum,h,k,p,x,y,vis[55][55];
  5. const int N=100005;
  6. map<char,ll>mp,mpp;
  7. string s,t;
  8. bool f;
  9. int main()
  10. {
  11. ios_base::sync_with_stdio(NULL);cin.tie(0);cout.tie(0);
  12.  
  13. cin>>n>>m;
  14. cin>>s>>t;
  15. for(int i=0;i<m;i++)
  16. mp[t[i]]++;
  17.  
  18. for(int r=0;r<n;r++)
  19. {
  20. mpp[s[r]]++;
  21.  
  22. while(mpp[s[r]]>mp[s[r]])
  23. mpp[s[l]]--,l++;
  24.  
  25. ans+=(r-l+1);
  26. }
  27.  
  28. cout<<ans<<endl;
  29. }
Success #stdin #stdout 0s 5324KB
stdin
4 3
aaab
aba
stdout
8