結果

問題 No.3016 unordered_mapなるたけ落とすマン
ユーザー Ryuhei MoriRyuhei Mori
提出日時 2020-05-23 17:07:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 67 ms / 1,000 ms
コード長 802 bytes
コンパイル時間 561 ms
コンパイル使用メモリ 55,296 KB
実行使用メモリ 19,200 KB
最終ジャッジ日時 2024-04-17 03:38:03
合計ジャッジ時間 6,470 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
16,028 KB
testcase_01 AC 5 ms
16,000 KB
testcase_02 AC 4 ms
16,128 KB
testcase_03 AC 57 ms
19,200 KB
testcase_04 AC 57 ms
18,944 KB
testcase_05 AC 56 ms
19,072 KB
testcase_06 AC 67 ms
19,072 KB
testcase_07 AC 63 ms
18,944 KB
testcase_08 AC 60 ms
19,072 KB
testcase_09 AC 55 ms
19,072 KB
testcase_10 AC 53 ms
19,092 KB
testcase_11 AC 54 ms
19,196 KB
testcase_12 AC 56 ms
19,160 KB
testcase_13 AC 53 ms
19,072 KB
testcase_14 AC 53 ms
18,944 KB
testcase_15 AC 54 ms
18,940 KB
testcase_16 AC 54 ms
19,072 KB
testcase_17 AC 53 ms
18,944 KB
testcase_18 AC 54 ms
18,996 KB
testcase_19 AC 60 ms
18,904 KB
testcase_20 AC 57 ms
19,064 KB
testcase_21 AC 54 ms
19,000 KB
testcase_22 AC 54 ms
19,140 KB
testcase_23 AC 52 ms
19,072 KB
testcase_24 AC 51 ms
18,988 KB
testcase_25 AC 50 ms
19,072 KB
testcase_26 AC 50 ms
19,048 KB
testcase_27 AC 50 ms
19,072 KB
testcase_28 AC 50 ms
19,072 KB
testcase_29 AC 51 ms
19,008 KB
testcase_30 AC 53 ms
18,944 KB
testcase_31 AC 53 ms
19,200 KB
testcase_32 AC 58 ms
19,200 KB
testcase_33 AC 55 ms
19,192 KB
testcase_34 AC 51 ms
19,108 KB
testcase_35 AC 50 ms
19,200 KB
testcase_36 AC 48 ms
19,072 KB
testcase_37 AC 49 ms
18,944 KB
testcase_38 AC 49 ms
18,976 KB
testcase_39 AC 50 ms
19,008 KB
testcase_40 AC 49 ms
18,816 KB
testcase_41 AC 4 ms
16,128 KB
testcase_42 AC 4 ms
15,872 KB
testcase_43 AC 4 ms
16,016 KB
testcase_44 AC 8 ms
16,428 KB
testcase_45 AC 7 ms
16,384 KB
testcase_46 AC 9 ms
16,256 KB
testcase_47 AC 46 ms
17,920 KB
testcase_48 AC 46 ms
18,020 KB
testcase_49 AC 44 ms
17,884 KB
testcase_50 AC 44 ms
15,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <array>
#include <vector>

using u32 = unsigned int;
using u64 = unsigned long long int;

template <typename T, int n>
class Hash {
  std::array<std::vector<std::pair<u64, T> >, 1<<(n+2)> v;

  u32 h(u64 a) const {
    static constexpr u64 r = 11995408973635179863ULL;
    return a * r >> (64 - (n+2));
  }

  public:
  T &operator[](u64 a){
    u32 i = h(a);
    for(auto &w: v[i]){
      if(w.first == a) return w.second;
    }
    v[i].emplace_back(a, T());
    return v[i].back().second;
  }
};

int n, m;

int main(){
  scanf("%d%d", &n, &m);

  Hash<u64, 17> h;
  for(int i = 0; i < n; i++){
    u64 a;
    scanf("%llu", &a);
    ++h[a];
  }
  for(int i = 0; i < m; i++){
    u64 a;
    scanf("%llu", &a);
    printf("%llu%c", h[a], " \n"[i == m-1]);
  }
  return 0;
}
0