fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. using ll = long long;
  5.  
  6. void solve() {
  7. int n; cin >> n;
  8. map<ll, int> cnt;
  9. cnt[0] = 1;
  10. ll sum = 0, ans = 0;
  11. for (int i = 0; i < n; i++) {
  12. int x; cin >> x;
  13. sum += x;
  14. ans += cnt[sum];
  15. cnt[sum]++;
  16. }
  17. cout << ans << '\n';
  18. }
  19.  
  20. int main() {
  21. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  22.  
  23. int tests = 1; // cin >> tests;
  24. while (tests--) solve();
  25.  
  26. #ifdef LOCAL
  27. cerr << "\nTime elapsed: " << clock() << " ms.\n";
  28. #endif
  29. return 0;
  30. }
Success #stdin #stdout 0s 5312KB
stdin
5
2 1 -1 -2 0
stdout
4