cin의 속도를 빠르게 하기 위해서 ios_base::sync_with_stdio(false); cin.tie(0);
를 추가해주고 다음을 사용해 풀이.upper_bound: 찾고 싶은 값을 초과하는 값이 처음 나오는 인덱스 (<)
lower_bound: 찾고 싶은 값 이상의 값이 처음 나오는 인덱스 (<=)
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
vector<int> v;
int n, m;
cin >> n;
int num;
for (int i = 0; i < n; i++)
{
cin >> num;
v.push_back(num);
}
sort(v.begin(), v.end());
cin >> m;
for (int i = 0; i < m; i++)
{
cin >> num;
cout << upper_bound(v.begin(), v.end(), num) - lower_bound(v.begin(), v.end(), num) << ' ';
}
return 0;
}