-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10611.cpp
46 lines (42 loc) · 1.08 KB
/
10611.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
#include <bits/stdc++.h>
using namespace std;
int n, num[50010], qnum, q;
int binSrc(int l, int h, int f){
int m;
while(l < h){
m = (l + h) / 2;
if(num[m] == f)h = h - 1;
else if(num[m] > f)h = m - 1;
else l = m + 1;
}return l;
}
int main()
{
//freopen("output.txt","w",stdout);
while(cin >> n){
for(int i = 0; i < n; i++)cin >> num[i];
cin >> qnum;
for(int i = 0; i < qnum; i++){
cin >> q;
int idx = binSrc(0, n-1, q);
//cout << idx << endl;
int a = -1, b = -1;
for(int j = idx; j >= 0; j--){
if(num[j] < q){
a = j;
break;
}
}
for(int j = idx; j < n; j++){
if(num[j] > q){
b = j;
break;
}
}
if(a == -1)cout << "X ";
else cout << num[a] << " ";
if( b == -1)cout << "X" << endl;
else cout << num[b] << endl;
}
}return 0;
}