fork download
  1. #include <bits/stdc++.h>
  2. #define boost ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  3. #define ll long long
  4. #define el cout << '\n'
  5. #define sz(a) (ll)a.size()
  6. #define all(a) a.begin(), a.end()
  7. #define file(name) \
  8.   if (fopen(name ".inp", "r")) \
  9.   { \
  10.   freopen(name ".inp", "r", stdin); \
  11.   freopen(name ".out", "w", stdout); \
  12.   }
  13. #define TIME (1.0 * clock() / CLOCKS_PER_SEC)
  14. #define RUNTIME cerr << "\nRuntime: " << TIME << "s.\n"
  15.  
  16. using namespace std;
  17.  
  18. const int N5 = 1e5 + 5;
  19. const ll MOD = 1e9 + 7;
  20. const ll inf = LLONG_MAX;
  21.  
  22. int n;
  23. ll s, pre[N5], cnt;
  24. multiset<ll> si;
  25.  
  26. void solve()
  27. {
  28. cin >> n >> s;
  29. for (int i = 1; i <= n; ++i)
  30. {
  31. ll x;
  32. cin >> x;
  33. pre[i] = pre[i - 1] + x;
  34. }
  35. for (int i = 1; i <= n; ++i)
  36. {
  37. auto it1 = si.lower_bound(pre[i] - s);
  38. auto it2 = si.upper_bound(pre[i] + s);
  39. cnt += distance(si.begin(), it1) + distance(it2, si.end());
  40. si.insert(pre[i]);
  41. }
  42.  
  43. cout << cnt;
  44. el;
  45. }
  46.  
  47. int main()
  48. {
  49. boost
  50. file("code");
  51. solve();
  52. RUNTIME;
  53. return 0;
  54. }
  55.  
Success #stdin #stdout #stderr 0.01s 5284KB
stdin
Standard input is empty
stdout
0
stderr
Runtime: 0.007322s.