๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm ๐Ÿง‘๐Ÿป‍๐Ÿ’ป/๋ฐฑ์ค€(BOJ)

[๋ฐฑ์ค€,c++] 10816๋ฒˆ - ์ˆซ์ž์นด๋“œ 2

by dkswnkk 2021. 10. 24.
 

10816๋ฒˆ: ์ˆซ์ž ์นด๋“œ 2

์ฒซ์งธ ์ค„์— ์ƒ๊ทผ์ด๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ์ˆซ์ž ์นด๋“œ์˜ ๊ฐœ์ˆ˜ N(1 ≤ N ≤ 500,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” ์ˆซ์ž ์นด๋“œ์— ์ ํ˜€์žˆ๋Š” ์ •์ˆ˜๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ˆซ์ž ์นด๋“œ์— ์ ํ˜€์žˆ๋Š” ์ˆ˜๋Š” -10,000,000๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 10,

www.acmicpc.net

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int N, M;
    cin >> N;
    vector<int>v;
    for (int i = 0; i < N; i++) {
        int number; cin >> number;
        v.push_back(number);
    }
    sort(v.begin(), v.end());
    int ans;
    cin >> M;
    for (int i = 0; i < M; i++) {
        int target; cin >> target;
        auto upper = upper_bound(v.begin(), v.end(), target);
        auto lower = lower_bound(v.begin(), v.end(), target);
        ans = upper - lower;
        cout << ans << " ";
        }
    }
    ```

๋Œ“๊ธ€