-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEasyQuery.java
More file actions
51 lines (47 loc) · 1.31 KB
/
Copy pathEasyQuery.java
File metadata and controls
51 lines (47 loc) · 1.31 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
package com.apostek;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class EasyQuery {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer tk = new StringTokenizer(br.readLine());
int n = Integer.parseInt(tk.nextToken());
int q = Integer.parseInt(tk.nextToken());
String str= br.readLine();
int a[] = new int[n];
for(int i=0;i<n;i++) {
a[i]=Integer.parseInt(str.split(" ")[i]);
}
while(q-->0) {
StringTokenizer tkType = new StringTokenizer(br.readLine());
int type = Integer.parseInt(tkType.nextToken());
int index = Integer.parseInt(tkType.nextToken());
if(type==0) {
int lIndex=index-1;
int rIndex=index+1;
while(lIndex>=0) {
if(a[lIndex]==1) {
break;
}
lIndex--;
}
while(rIndex<n) {
if(a[rIndex]==1) {
break;
}
rIndex++;
}
if(rIndex==n) {
rIndex=-1;
}
System.out.println(lIndex+" "+rIndex);
}else {
if(a[index]==0) {
a[index]=1;
}
}
}
}
}