-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOneTwo.cpp
57 lines (51 loc) · 1.11 KB
/
OneTwo.cpp
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <bits/stdc++.h>
using namespace std;
/*
array element only 1 and 2.
1 <= test <= 5;
1 <= N <= 2*10^6;
find no. of contiguous subseq. of sum == s;
where
0 <= s <= 2*N;
*/
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int test;
cin >> test;
for(int t = 0; t < test; t++)
{
long int N;
cin >> N;
long int sum[N] = {0}, s[2*N+1] = {0};
int a[N];
for(long int n = 0; n < N; n++)
{
cin >> a[n];
if(n == 0){
sum[n] = a[n];
}else{
sum[n] = sum[n-1] + a[n];
}
for(long int i = 0; i <= n; i++)
{
if(i == 0)
{
s[sum[n]]++;
}else{
s[sum[n] - sum[i-1]]++;
}
}
}
long int count = 0;
for(long int j = 0; j < 2*N + 1; j++)
{
if(s[j] == 0){
count++;
}
}
cout << 2*N + 1 - count << "\n";
}
return 0;
}