結果

問題 No.3016 ハチマキおじさん
ユーザー lam6er
提出日時 2025-04-15 22:58:16
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,207 bytes
コンパイル時間 2,118 ms
コンパイル使用メモリ 202,820 KB
実行使用メモリ 10,632 KB
最終ジャッジ日時 2025-04-15 22:59:57
合計ジャッジ時間 4,938 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, M;
    cin >> N >> M;

    vector<long long> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    vector<pair<long long, int>> counts;
    if (N == 0) {
        counts = {};
    } else {
        int current_count = 1;
        for (int i = 1; i < N; ++i) {
            if (A[i] == A[i-1]) {
                current_count++;
            } else {
                counts.emplace_back(A[i-1], current_count);
                current_count = 1;
            }
        }
        counts.emplace_back(A.back(), current_count);
    }

    for (int i = 0; i < M; ++i) {
        long long b;
        cin >> b;
        auto it = lower_bound(counts.begin(), counts.end(), make_pair(b, 0),
                              [](const pair<long long, int>& x, const pair<long long, int>& y) {
                                  return x.first < y.first;
                              });
        if (it != counts.end() && it->first == b) {
            cout << it->second << " ";
        } else {
            cout << "0 ";
        }
    }

    return 0;
}
0