Skip to content

Commit 2754f46

Browse files
authored
greedy
1 parent f9756dc commit 2754f46

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

codeforce/1718A2_greedy.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//greedy
2+
#include <stdio.h>
3+
#include <set>
4+
using namespace std;
5+
int a[100001];
6+
int main() {
7+
int t;
8+
for (scanf("%d", &t); t--;) {
9+
int i, n;
10+
for (scanf("%d", &n), i = 1; i <= n; ++i) scanf("%d",a+i),a[i]^=a[i-1];
11+
set<int> st; st.insert(0);
12+
int ans = n;
13+
for (i = 1; i <= n; ++i) {
14+
if (st.find(a[i]) != st.end()) {
15+
--ans; st.clear();
16+
}
17+
st.insert(a[i]);
18+
}
19+
printf("%d\n",ans);
20+
}
21+
22+
return 0;
23+
}

0 commit comments

Comments
 (0)