fork download
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4. ll n,k,kq = 0,t = 0,l,h,m,a[100005],vt = 0;
  5. string s;
  6. int main()
  7. {
  8. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  9. freopen("XAUCON.inp", "r", stdin);
  10. freopen("XAUCON.out", "w", stdout);
  11. cin >> n >> k;
  12. cin >> s;
  13. for(int i = 1; i <= n; i++)
  14. {
  15. a[i] = a[i-1] + (int)(s[i-1]);
  16. }
  17. for(int i = 1; i <= n; i++)
  18. {
  19. l = i, h = n,vt = i-1;
  20. while(l <= h)
  21. {
  22. m = (l+h)>>1;
  23. if(a[m] - a[i-1] >= k)
  24. {
  25. h = m - 1;
  26. vt = m;
  27. }
  28. else l = m + 1;
  29. }
  30. if(vt != i-1)
  31. kq += n - vt + 1;
  32. }
  33. cout << kq;
  34. }
  35.  
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty