-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCF_1333C.cpp
More file actions
43 lines (38 loc) · 851 Bytes
/
CF_1333C.cpp
File metadata and controls
43 lines (38 loc) · 851 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <functional>
#include <cstdlib>
#include <list>
#include <iomanip>
#define ll long long
using namespace std;
int main() {
int n;
cin >> n;
vector<ll> prefix(n + 1, 0);
for (int i = 0; i < n; ++i) {
int num;
cin >> num;
prefix[i + 1] = prefix[i] + num;
}
int begin = 1, end = 0;
long long ans = 0;
set<long long> s = { 0 };
while (begin < n) {
while (end < n && !s.count(prefix[end + 1])) {
end++;
s.insert(prefix[end]);
}
ans += end - begin;
s.erase(prefix[begin]);
begin++;
}
cout << ans << endl;
}