-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUva12356.java
More file actions
49 lines (49 loc) · 1.17 KB
/
Copy pathUva12356.java
File metadata and controls
49 lines (49 loc) · 1.17 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
import java.io.*;
import java.util.*;
// will gives TLE , you can use cpp .
public class Uva12356
{
public static void main(String [] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pr = new PrintWriter(System.out);
StringBuilder sb = new StringBuilder();
while(true)
{
StringTokenizer st = new StringTokenizer(br.readLine());
int s = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
if(s==0) break;
int [] left = new int[s+1];
int [] right = new int[s+1];
for(int i = 1 ; i <= s ; i++)
{
left[i]=i-1;
right[i]=i+1;
}
left[1] = right[s] = -1 ;
while(b-->0)
{
st = new StringTokenizer(br.readLine());
int l = Integer.parseInt(st.nextToken());
int r = Integer.parseInt(st.nextToken());
if(left[l]==-1)
sb.append("* ");
else
sb.append(left[l]+" ");
if(right[r]==-1)
sb.append("*\n");
else
sb.append(right[r]+"\n");
if(right[r]!=-1)
left[right[r]] = left[l];
if(left[l]!=-1)
right[left[l]] = right[r];
}
sb.append("-\n");
}
pr.print(sb.toString());
pr.close();
br.close();
}
}