Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //author @ Ayush Aggarwal
- // Let's Do this shit.
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- int main()
- {
- ios::sync_with_stdio(false);
- cin.tie(NULL);
- ll t;
- cin>>t;
- while(t--)
- {
- map <ll,ll> mp;
- mp.clear();
- mp[0]++;
- ll sum=0,n,k,ans=0;
- cin>>n>>k;
- ll a[n];
- string str;
- cin>>str;
- for(ll i=0;i<n;i++)
- {
- a[i] = str[i] - (ll)'a' + 49;
- //cout<<a[i]<<endl;
- sum +=a[i];
- //cout<<sum<<endl;
- ans +=mp[sum-k];
- //cout<<ans<<endl;
- mp[sum]++;
- // cout<<mp[sum]<<endl;
- }
- cout<<ans<<endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment