10815랑 똑같은데 수의 범위만 다른 문제였다. 마찬가지로 이분탐색으로 풀어도 되지만 이번에는 해시를 이용한 집합과 맵, unordered_map으로 풀이하였다.
#include<iostream>
#include<unordered_map>
#include<vector>
using namespace std;
int main(){
ios_base :: sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, m;
unordered_map<long long, int> um;
cin>>n;
vector<long long> v(100005);
for(int i=0; i<n; i++){
cin>>v[i];
um[v[i]]=1;
}
cin>>m;
for(int i=0; i<m; i++){
cin>>v[i];
if(um[v[i]]==1)
cout<<"1"<<"\n";
else
cout<<"0"<<"\n";
}
}
이때, 벡터의 크기를 올바르게 설정해 off the bound를 방지하는 것이 중요하다.
'알고리즘' 카테고리의 다른 글
| Boj 1990 c++소수인 팰린드롬 (0) | 2025.05.26 |
|---|---|
| Boj 1747 c++ 소수&팰린드롬 (0) | 2025.05.25 |
| Boj 32201 c++ 눈사람(해시) (0) | 2025.05.24 |
| Boj 1193 c++눈물의 노가다 (0) | 2025.05.23 |
| Boj 11659 c++ 구간 합 구하기 4 (0) | 2025.05.22 |