Advertisement
Josif_tepe

Untitled

Feb 26th, 2024
639
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2. //#include <bits/stdc++.h>
  3. #include <fstream>
  4. #include <algorithm>
  5. #include <set>
  6. #include <vector>
  7. #include <map>
  8. typedef long long ll;
  9. using namespace std;
  10.  
  11.  
  12. int main() {
  13.     int n, k;
  14.     cin >> n;
  15.    
  16.     vector<int> v(n);
  17.     for(int i = 0; i < n; i++) {
  18.         cin >> v[i];
  19.     }
  20.     map<ll, ll> cnt;
  21.     ll sum = 0, res = 0;
  22.     for(int i = 0; i < n; i++) {
  23.         sum += v[i];
  24.         if(sum == 0) {
  25.             res++;
  26.         }
  27.         if(cnt.count(sum)) {
  28.             res += cnt[sum];
  29.         }
  30.         cnt[sum]++;
  31.     }
  32.     cout << res << endl;
  33.         return 0;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement