-
Notifications
You must be signed in to change notification settings - Fork 0
/
bj_10815_numbercard
53 lines (47 loc) · 1.24 KB
/
bj_10815_numbercard
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
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <list>
#include <cmath>
using namespace std;
//bool naerim(int a, int b) {return a > b;}
long long int mycard_arr[500000];
int main(void)
{
int mycard_count;
int yourcard_count;
long long int value;
int start, end, mid;
cin>>mycard_count;
for(int i=0; i<mycard_count; i++) {
scanf("%lld", &mycard_arr[i]);
}
sort(mycard_arr, mycard_arr + mycard_count);
cin>>yourcard_count;
for(int i=0; i<yourcard_count; i++) {
start = 0;
end = mycard_count;
mid = (start + end) / 2;
scanf("%lld", &value);
while(1) {
if(mycard_arr[mid] < value) { // value is bigger than middle
start = mid + 1;
}
else if(mycard_arr[mid] > value) { // value is smaller than middle
end = mid - 1;
}
else {
printf("1 ");
break;
}
if((value < mycard_arr[0] || value > mycard_arr[mycard_count - 1]) || (start > end)) {
printf("0 ");
break;
}
mid = (start + end) / 2;
}
}
return 0;
}