-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10815.cpp
More file actions
53 lines (49 loc) · 895 Bytes
/
10815.cpp
File metadata and controls
53 lines (49 loc) · 895 Bytes
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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> v;
vector<int> s;
int flag = 0;
int search(int low, int high, int num){
int mid = (low+high)/2;
if(low==high){
return 0;
}
if(v[mid]==num){
flag=1;
return 0;
}
else if(v[mid]<num){
search(mid+1,high,num);
}
else{
search(low,mid,num);
}
return 0;
}
int main(int argc, char** argv)
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int num,n,m;
cin>>n;
for (int i = 0; i < n; ++i)
{
cin>>num;
v.push_back(num);
}
cin>>m;
for (int i = 0; i < m; ++i)
{
cin>>num;
s.push_back(num);
}
sort(v.begin(),v.end());
for (int i = 0; i < m; ++i)
{ flag = 0;
search(0,v.size(),s[i]);
cout<<flag<<" ";
}
}