forked from ashutosh97/Competitive-Programming-questions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodechef.java
78 lines (52 loc) · 1.87 KB
/
codechef.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import java.util.*;
import java.io.*;
class codechef
{
public static void main(String args[])throws IOException
{
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
int t= Integer.parseInt(br.readLine());
for(int phi=0; phi<t;phi++)
{
int n= Integer.parseInt(br.readLine());
String ra= br.readLine();
String zo= br.readLine();
int radpow[]= new int[n];
int starting[]= new int[n];
for(int i=0;i<n;i++)
{
starting[i]=0;
}
StringTokenizer st = new StringTokenizer(ra);
int cou=0;
while(st.hasMoreTokens())
{
long val = Long.parseLong(st.nextToken());
int start= (int)Math.max(0, cou-val);
int stop= (int)(cou+val+1);
cou++;
starting[start]+=1;
if(stop<=n-1)
starting[stop]-=1;
}
cou=0;
for(int i=0;i<n;i++)
{
cou+=starting[i];
if(cou<0)
cou=0;
radpow[i]+=cou;
}
StringTokenizer newst= new StringTokenizer(zo);
long xor=0;
for(int i=0;i<n;i++)
{
xor= (xor^radpow[i])^Long.parseLong(newst.nextToken());
}
if(xor==0)
System.out.println("YES");
else
System.out.println("NO");
}
}
}