-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathks1.cpp
More file actions
102 lines (79 loc) · 2.1 KB
/
ks1.cpp
File metadata and controls
102 lines (79 loc) · 2.1 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <unordered_map>
#include <list>
using namespace std ;
int main() {
int t ;
cin >> t ;
while ( t-- ) {
int n;
bool f= 0 ;
cin >> n ;
vector< int > v(n), xor1(n+1), sum(n,0) ;
for ( auto i = 0 ; i < n ; ++i ) {
cin >> v[i] ;
if ( f ) {
sum[i] = sum[i-1] + v[i] ;
}
else f=1 ;
}
xor1[0] = 0 ;
for ( auto i = 0 ; i < n ; ++i ) {
xor1[i+1] = xor1[i]^v[i] ;
}
int ans = 0 ;
unordered_map< int, vector< int > > h ;
for ( auto i = 0 ; i < n+1 ; ++i )
h[xor1[i]].push_back( i ) ;
//for ( auto i : xor1 )
//cout << i << ' ' ;
for ( auto i : h ) {
f = 0 ;
int prev=0, next ;
for ( auto j : i.second ) {
if ( f!=0 ) {
next = j ;
ans += next-prev-1 ;
prev = next ;
//if ( i.first == 0 )
//ans += next + prev ;
}
else {
prev = j ;
f = 1;
}
}
}
cout << ans << '\n' ;
}
}
/*
unordered_map< int, vector< int > > h ;
for ( auto i = 0 ; i < n ; ++i )
h[xor1[i]].push_back( i ) ;
for ( auto i : xor1 ) {
cout << i << ' ' ;
}
cout << "\n\n\n";
cout << '\n' << '\n' ;
for ( auto i : h ) {
f = 0 ;
int prev, next ;
for ( auto j : i.second ) {
if ( f==0 ) {
f=1 ;
continue ;
prev = j ;
}
next = j ;
ans += next-prev ;
if ( i.first == 0 ) {
ans += next + prev ;
}
prev = next ;
}
}
*/