-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1244.java
47 lines (38 loc) · 1.35 KB
/
1244.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
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int N = Integer.parseInt(br.readLine());
String[] S = br.readLine().split(" ");
int[] swch = new int[N];
for(int i=0; i<N; i++)
swch[i] = Integer.parseInt(S[i]);
int M = Integer.parseInt(br.readLine());
String[] command;
for(int m=0; m<M; m++) {
command = br.readLine().split(" ");
if(command[0].equals("1")) {
int mul = Integer.parseInt(command[1]);
for(int i=mul; i<=N; i+=mul)
swch[i - 1] ^= 1;
} else {
int mid = Integer.parseInt(command[1]) - 1;
int i=0;
while(0 <= mid - i && mid + i < N && swch[mid + i] == swch[mid - i]) {
swch[mid + i] ^= 1;
swch[mid - i] ^= 1;
i++;
}
swch[mid] ^= 1;
}
}
for(int i=0; i<N; i++) {
bw.write(swch[i] + " ");
if(i % 20 == 19)
bw.write("\n");
}
bw.flush();
bw.close();
}
}