Created
April 22, 2020 19:51
-
-
Save fardinabir/73ebbe75280ce2d098e6b715772e07db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define mx 1000005 | |
#define ll long long int | |
#define test_case printf("Case %d:\n",id++); | |
using namespace std; | |
ll arr[mx],pre_sum[mx],n; | |
vector <ll> node[4*mx]; | |
int main() | |
{ | |
ll t,i,j,k,l,a,b,c=0,p,d=0,e,u,v,q,sum,id=1,x,y; | |
cin>>t; | |
while(t--) | |
{ | |
c=0; | |
scanf("%lld",&n); | |
map <ll,ll> mp; | |
for(i=1;i<=n;i++) | |
{ | |
scanf("%lld",&a); | |
pre_sum[i]+=(pre_sum[i-1]+a); | |
mp[pre_sum[i]]++; | |
} | |
for(i=1;i<=n;i++) | |
{ | |
c+=mp[pre_sum[i-1]]; | |
mp[pre_sum[i]]--; | |
} | |
cout<<c<<endl; | |
memset(pre_sum,0,sizeof pre_sum); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment