-
Notifications
You must be signed in to change notification settings - Fork 2
/
Q10611.cpp
55 lines (49 loc) · 923 Bytes
/
Q10611.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
#include <stdio.h>
int s[50010],n;
int main() {
int i,j,q,target,len;
int st,ed,mid;
scanf("%d",&n);
for(i=len=0;i<n;i++) {
scanf("%d",&j);
if(s[len-1] != j) s[len++] = j;
}
scanf("%d",&q);
while(q--) {
scanf("%d",&target);
st = 0, ed = len;
while(st < ed) {
mid = (st+ed)/2;
if(s[mid] == target)
break;
else if(s[mid] < target)
st = mid+1;
else
ed = mid;
}
if(st >= ed) {
if(ed == 0) {
printf("X %d\n",s[0]);
continue;
}
if(st >= len) {
printf("%d X\n",s[len-1]);
continue;
}
printf("%d %d\n",s[ed-1],s[ed]);
} else {
if(mid == 0 && mid == len-1) {
printf("X X\n");
continue;
}
if(mid == 0) {
printf("X %d\n",s[mid+1]);
} else if(mid == len-1) {
printf("%d X\n",s[mid-1]);
} else {
printf("%d %d\n",s[mid-1],s[mid+1]);
}
}
}
return 0;
}