처음에는 모든 값을 저장하려고 반복문을 돌려서 시간초과가 발생했다. 시간을 줄이기 위해 두번째 자료는 저장하지 않고 입력때마다 바로 결과를 출력했다.
#include <iostream>
//#include <vector>
#include <map>
//#include <algorithm>
#include <unordered_map>
using namespace std;
/*
void find_answer(map<int, bool>& note1, vector<int>& note2)
{
for (int i : note2)
{
if (note1[i] == true)
{
cout << "1\n";
}
else
{
cout << "0\n";
}
}
return;
}
*/
void solution()
{
int i, T, j;
int N, M, temp;
cin >> T;
for (i = 0; i < T; i++)
{
unordered_map<int, bool> note1;
//vector<int> note2;
cin >> N;
for (j = 0; j < N; j++)
{
cin >> temp;
note1[temp] = true;
}
cin >> M;
for (j = 0; j < M; j++)
{
cin >> temp;
//note2.push_back(temp);
if (note1[temp] == true)
{
cout << "1\n";
}
else
{
cout << "0\n";
}
}
//find_answer(note1, note2);
}
return;
}
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
solution();
return 0;
}