백준 알고리즘 10816번 : 숫자 카드 2

Zoo Da·2021년 11월 21일
0

백준 알고리즘

목록 보기
260/337
post-thumbnail

링크

https://www.acmicpc.net/problem/10816

sol1) 이분탐색 STL

#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define int int64_t
using namespace std;

int32_t main() {
  fastio;
  int n,m; cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  cin >> m;
  for(int i = 0; i < m; i++){
    int t; cin >> t;
    cout << (upper_bound(a.begin(), a.end(), t) - lower_bound(a.begin(), a.end(), t)) << " ";
  }
  return 0;
}
profile
메모장 겸 블로그

0개의 댓글