C. Eugene and an array Codeforces Round #632 (Div. 2)

C. Eugene and an array Codeforces Round #632 (Div. 2)_第1张图片

传送门

#include <bits/stdc++.h>
#define ll long long 
using namespace std;
const int maxn=2e5+10;
 
int n,x;
map<ll,int> m;
 
int main()
{
	scanf("%d",&n);
	ll pref=0,ans=0;
	int l=0;
	m[0]=0;
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&x);
		pref+=x;
		if(m.count(pref))
			l=max(l,m[pref]+1);
		ans+=i-l;
		m[pref]=i;
	}	
	printf("%lld\n",ans);
	return 0;
}

你可能感兴趣的:(思维)