10816 숫자 카드2[lowerbound upperbound]

박호준·2022년 1월 15일
0

Baekjoon

목록 보기
5/10

10816 숫자카드2
https://www.acmicpc.net/problem/10816

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	vector<long long> vec;
	int		N,M;
	long long temp;
	cin >> N;
	while (N--)
	{
		cin >> temp; vec.push_back(temp);
	}
	sort(vec.begin(), vec.end());
	cin >> M;
	while (M--)
	{
		cin >> temp;
		cout << upper_bound(vec.begin(), vec.end(), temp) - lower_bound(vec.begin(), vec.end(), temp) << " ";
	}
}

lowerbound와 upperbound를 이용하여 이분탐색으로 원하는 수를 찾고, 그 수의 개수를 찾을 수 있다.

profile
hopark

0개의 댓글