Advertisement
nguyentien281006

SUMSEQ0

Oct 22nd, 2022
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define int long long
  3. using namespace std;
  4.  
  5. int c(int k, int n) {
  6.     int a = 1, b = 1;
  7.     for (int i = 1; i <= k; i++) {
  8.         b *= i;
  9.     }
  10.     for (int i = n - k + 1; i <= n; i++) {
  11.         a *= i;
  12.     }
  13.     return a / b;
  14. }
  15.  
  16. int n, a[100005], p[100005], cnt = 0;
  17. signed main() {
  18.     ios::sync_with_stdio(false);
  19.     cin.tie(nullptr);
  20.     // freopen("SUMSEQ0.inp", "r", stdin);
  21.     // freopen("SUMSEQ0.out", "w", stdout);
  22.     map<int, int> m;
  23.     cin >> n;
  24.     for (int i = 0; i < n; i++) {
  25.         cin >> a[i];
  26.         if (i == 0)
  27.             p[i] = a[i];
  28.         else
  29.             p[i] = p[i - 1] + a[i];
  30.         m[p[i]]++;
  31.     }
  32.  
  33.     for (auto &i : m) {
  34.         if (i.first == 0) {
  35.             cnt += i.second;
  36.             if (i.second >= 2)
  37.                 cnt += c(2, i.second);
  38.         } else if (i.second >= 2)
  39.             cnt += c(2, i.second);
  40.     }
  41.     cout << cnt;
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement