Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- //#include <bits/stdc++.h>
- #include <fstream>
- #include <algorithm>
- #include <set>
- #include <vector>
- #include <map>
- typedef long long ll;
- using namespace std;
- int main() {
- int n, k;
- cin >> n;
- vector<int> v(n);
- for(int i = 0; i < n; i++) {
- cin >> v[i];
- }
- map<ll, ll> cnt;
- ll sum = 0, res = 0;
- for(int i = 0; i < n; i++) {
- sum += v[i];
- if(sum == 0) {
- res++;
- }
- if(cnt.count(sum)) {
- res += cnt[sum];
- }
- cnt[sum]++;
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement