링크 : https://www.acmicpc.net/problem/10815
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int binarySearch(vector<int>&v, int target, int start, int end){
while(start <= end){
int mid = (start + end) / 2;
if(v[mid] == target) return mid;
else if (v[mid] > target) end = mid - 1;
else start = mid + 1;
}
return -1;
}
int main(){
int N, M;
cin >> N;
vector<int> v;
for(int i = 0; i < N; i++){
int x;
cin >> x;
v.push_back(x);
}
sort(v.begin(), v.end());
cin >> M;
vector<int> s;
for(int i = 0; i < M; i++){
int x;
cin >> x;
s.push_back(x);
}
for(int i = 0; i < M; i++){
int result = binarySearch(v, s[i], 0, N-1);
if(result != -1) cout << "1 ";
else cout << "0 ";
}
return 0;
}