-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12356.cpp
58 lines (45 loc) · 852 Bytes
/
12356.cpp
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
#include "bits/stdc++.h"
//#include <bits/stdc++.h>
// 1 2 3 4 5 6 7 8 9 10
// 2 3 4 5 6 7 8 9 10 0 right
// 0 1 2 3 4 5 6 7 8 9 left
/*
1 1
1 1
10 4
2 5
6 9
1 1
10 10
5 1
1 1
0 0
*/
using namespace std;
int main () {
int s, b;
while (scanf ("%d %d", &s,&b) != EOF) {
if (s == 0 & b == 0) break;
int right [100100] = {0};
int left [100100] = {0};
for (int i = 1; i <= s; ++i) {
right[i] = i + 1;
left[i] = i - 1;
}
while (b--) {
int l, r;
scanf("%d %d",&l,&r);
if (left[l] == 0) printf("* ");
else {
printf("%d ",left[l]);
}
if (right[r] == 0 || right[r] > s) printf("*\n");
else {
printf("%d\n",right[r]);
}
right[left[l]] = right[r];
left[right[r]] = left[l];
}
printf("-\n");
}
}