Josif_tepe

Untitled

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