Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <queue>
- #include <map>
- #include <stack>
- using namespace std;
- typedef long long ll;
- const int maxn = 1e5 + 10;
- int main() {
- ios_base::sync_with_stdio(false);
- int n;
- cin >> n;
- vector<int> v(n);
- for(int i = 0; i< n; i++) {
- cin >> v[i];
- }
- map<ll, ll> cnt;
- ll res = 0, sum = 0;
- for(int i = 0; i < n; i++) {
- sum += v[i];
- if(sum == 0) {
- res++;
- }
- res += cnt[sum];
- cnt[sum]++;
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment