fork download
  1. #include<bits/stdc++.h>
  2. #define f1(i, n) for(int i=1;i<=n;++i)
  3. #define f0(i, n) for(int i=0;i<n;++i)
  4. #define ull unsigned long long
  5. #define ll long long
  6. #define rev(a) reverse(a.begin(),a.end())
  7. #define all(x) x.begin(),x.end()
  8. #define so(A, n) sort(A+1, A+n+1)
  9. using namespace std;
  10. const int maxn = 1e7 + 1;
  11. ll T[maxn];
  12. map<ll, ll> tru, mp;
  13. int main() {
  14. ios_base::sync_with_stdio(0);
  15. cin.tie(0);
  16. cout.tie(0);
  17. int n;
  18. ll x;
  19. cin >> n;
  20. mp[0] = 1;
  21. f1(i, n) {
  22. cin >> x;
  23. T[i] = T[i - 1] + x;
  24. mp[T[i]]++;
  25. if (T[i] == T[i - 1]) {
  26. tru[T[i]]++;
  27. }
  28. }
  29. int cnt = 0;
  30. for (auto it : mp) {
  31. cnt += (it.second * (it.second - 1) / 2) - tru[it.first];
  32. }
  33. cout << cnt;
  34. return 0;
  35.  
  36.  
  37. }
  38.  
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty