-
toc {:toc}
νμ΄
λ¨μ μ ν νμμΌλ‘ μ°Ύλ λ°©μμ μκ°λ³΅μ‘λκ° λμ ν μ μλ€. λ€μμ λ°©λ²μΌλ‘ μ΄μ§ νμμ μ νν μ μλ€. μλμ²λΌ μ¬κ·μ μΈ λ°©μμΌλ‘ νμ΄νλ€. νμ§λ§ κ²½νμ μ¬κ·μ μΈ λ°©μμ λ°λ³΅λ¬Έμ μ¬μ©ν λ°©μμ λΉν΄ μκ°λ³΅μ‘λκ° λ λκ² μΈ‘μ λλ κ²½μ°κ° λ§λ€. μΌλ°μ μΌλ‘λ λ°λ³΅λ¬Έμ μ¬μ©ν μ΄μ§ νμ λ°©μμ μ¬μ©νμ.
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL N, M;
int res, check = 0, idx = 0;
vector<int> vec;
int search(vector<int>& v, int num, int s, int e){
if (s > e) return 0;
int mid = (s + e) / 2;
if (v[mid] == num) return 1;
else if (v[mid] > num) return search(v, num, s, mid-1);
else return search(v, num, mid+1, e);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> N;
int ins = 0;
int val;
for(int i=0; i<N; i++){
cin >> val;
vec.push_back(val);
}
sort(vec.begin(), vec.end());
cin >> M;
while (M--) {
res = 0;
cin >> val;
res = search(vec, val, 0, vec.size()-1);
if (res) cout << 1 << '\n';
else cout << 0 << '\n';
}
return 0;
}