-
Notifications
You must be signed in to change notification settings - Fork 0
/
BearAndXorOfSums.java
57 lines (46 loc) · 1.34 KB
/
BearAndXorOfSums.java
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
package problems.codechef;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
/**
* Created by arpit on 23/4/17.
*/
public class BearAndXorOfSums {
static byte a[]=new byte[300000];
static int prefix[]=new int[300000];
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t,n;
String[]s;
n = Integer.parseInt(br.readLine());
s=br.readLine().split("\\s");
for (int i = 0; i < n; i++) {
a[i]=Byte.parseByte(s[i]);
}
System.out.println(solve(a,n));
}
private static int solve(byte[] a, int n) {
calPrefix(a,n);
/*for (int i = 0; i < n; i++) {
System.out.print(prefix[i] + " ");
}
System.out.println();*/
int result=0,diff,sum;
for (int i = 0; i < n; i++) {
diff=0;
for (int j = 0; j <= i; j++) {
sum = prefix[i]-diff;
result ^= sum;
diff = prefix[j];
}
}
return result;
}
private static void calPrefix(byte[] a, int n) {
prefix[0]=a[0];
for (int i = 1; i <n; i++) {
prefix[i] = prefix[i - 1] + a[i];
}
}
}