Binary Search 10816

#C++

C++ 코드

// 18870
//10816 lower bound and upper bound
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, m;
cin >> n;
vector<int>a(n);
for(int i = 0; i < n; i++)
{
cin >> a[i];
}
cin >> m;
vector<int>b(m);
for(int i = 0; i < m; i++)
{
cin >> b[i];
}
sort(a.begin(), a.end());
vector<int> count(m);
for(int i = 0; i < m; i++)
{
int lower = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
int upper = upper_bound(a.begin(), a.end(), b[i]) - a.begin();
count[i] = upper - lower;
}
for(int i = 0; i < m; i++)
{
cout << count[i] << " ";
}
return 0;
}

© 2026 aaarlaguswns

연결된 글 전체 그래프 드래그로 이동 · 휠로 확대 · 점을 누르면 그 글로