fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int maxn = 1e6;
  6.  
  7. int n, m, a[maxn+1];
  8. long long ans = 0;
  9. vector<int> v;
  10.  
  11. void sub1()
  12. {
  13. for (int i = 1; i <= n; i++)
  14. {
  15. bool check = 0;
  16. for (int j = i; j <= n; j++)
  17. {
  18. if (a[j] >= m) check = 1;
  19. if (check)
  20. {
  21. ans++;
  22. continue;
  23. }
  24. }
  25. }
  26. cout << ans;
  27. }
  28.  
  29. void sub3()
  30. {
  31. int l = 1, r;
  32. for (r = 1; r <= n; r++)
  33. {
  34. if (a[r] >= m) v.push_back(r);
  35. int vsize = v.size();
  36. while (vsize > 0)
  37. {
  38. ans += n - r + 1;
  39. if (a[l] >= m) v.erase(v.begin(), v.begin() + 1);
  40. l++;
  41. vsize = v.size();
  42. }
  43. }
  44. cout << ans;
  45. }
  46.  
  47. int main()
  48. {
  49. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  50. freopen("COUNT.INP", "r", stdin);
  51. freopen("COUNT.OUT", "w", stdout);
  52. cin >> n >> m;
  53. for (int i = 1; i <= n; i++) cin >> a[i];
  54. if (n <= 1e3) sub1();
  55. else sub3();
  56. }
  57.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty