結果

問題 No.3016 unordered_mapなるたけ落とすマン
ユーザー tonegawatonegawa
提出日時 2020-11-24 18:20:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 88 ms / 1,000 ms
コード長 5,660 bytes
コンパイル時間 1,369 ms
コンパイル使用メモリ 121,936 KB
実行使用メモリ 9,932 KB
最終ジャッジ日時 2023-10-01 01:08:47
合計ジャッジ時間 9,093 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,504 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 79 ms
9,752 KB
testcase_04 AC 88 ms
9,932 KB
testcase_05 AC 87 ms
9,888 KB
testcase_06 AC 86 ms
9,708 KB
testcase_07 AC 86 ms
9,732 KB
testcase_08 AC 87 ms
9,736 KB
testcase_09 AC 86 ms
9,744 KB
testcase_10 AC 86 ms
9,884 KB
testcase_11 AC 87 ms
9,880 KB
testcase_12 AC 86 ms
9,740 KB
testcase_13 AC 85 ms
9,736 KB
testcase_14 AC 85 ms
9,696 KB
testcase_15 AC 85 ms
9,772 KB
testcase_16 AC 85 ms
9,796 KB
testcase_17 AC 85 ms
9,804 KB
testcase_18 AC 85 ms
9,736 KB
testcase_19 AC 85 ms
9,736 KB
testcase_20 AC 85 ms
9,708 KB
testcase_21 AC 84 ms
9,668 KB
testcase_22 AC 84 ms
9,700 KB
testcase_23 AC 83 ms
9,700 KB
testcase_24 AC 83 ms
9,748 KB
testcase_25 AC 82 ms
9,788 KB
testcase_26 AC 80 ms
9,660 KB
testcase_27 AC 80 ms
9,740 KB
testcase_28 AC 79 ms
9,796 KB
testcase_29 AC 79 ms
9,820 KB
testcase_30 AC 78 ms
9,708 KB
testcase_31 AC 77 ms
9,784 KB
testcase_32 AC 75 ms
9,720 KB
testcase_33 AC 73 ms
9,680 KB
testcase_34 AC 74 ms
9,640 KB
testcase_35 AC 72 ms
9,752 KB
testcase_36 AC 72 ms
9,668 KB
testcase_37 AC 70 ms
9,724 KB
testcase_38 AC 70 ms
9,724 KB
testcase_39 AC 69 ms
9,672 KB
testcase_40 AC 69 ms
9,688 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 7 ms
4,380 KB
testcase_45 AC 7 ms
4,380 KB
testcase_46 AC 7 ms
4,380 KB
testcase_47 AC 75 ms
7,300 KB
testcase_48 AC 82 ms
7,620 KB
testcase_49 AC 82 ms
7,620 KB
testcase_50 AC 41 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <cassert>
#include <iomanip>
#include <numeric>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;


template<typename Key>
struct hashset{
  float load_factor = 0.8;
  int table_size = 16;
  int mod = 15;
  Key null_key;
  vector<Key> table;
  vector<Key> data;
  function<uint32_t(Key)> f = std::hash<uint32_t>();
  hashset():
    null_key(std::numeric_limits<Key>::max()),
    table(table_size, null_key){}
  int size(){
    return data.size();
  }
  void expand_table(){
    table_size *= 2;
    mod = table_size - 1;
    table.resize(table_size);
    fill(table.begin(), table.end(), null_key);
    for(auto v:data) insert(v, false);
  }
  void insert(Key k, bool g=true){
    assert(k!=null_key);
    uint32_t h = f(k) & mod;
    while(true){
      if(table[h]!=null_key){
        if(table[h]==k) return;
        h = (h + 1) & mod;
      }else{
        if(g) data.push_back(k);
        table[h] = k;
        if(float(data.size())>load_factor*float(table_size)){
          expand_table();
        }
        return;
      }
    }
  }
  bool contain(Key k){
    unsigned h = f(k) & mod;
    while(true){
      if(table[h]==null_key) return false;
      if(table[h]==k) return true;
      h = (h + 1) & mod;
    }
  }
};

template<typename Key, typename Val>
struct hashmap{
  float load_factor = 0.8;
  int table_size = 16;
  int mod = 15;
  Key null_key;
  vector<Key> key_table;
  vector<Val> val_table;
  vector<pair<Key, Val>> data;
  function<uint32_t(Key)> f = std::hash<uint32_t>();

  hashmap():
    null_key(std::numeric_limits<Key>::max()),
    key_table(table_size, null_key), val_table(table_size){}
  int size(){
    return data.size();
  }
  void expand_table(){
    table_size *= 2;
    mod = table_size - 1;
    key_table.resize(table_size);
    val_table.resize(table_size);
    fill(key_table.begin(), key_table.end(), null_key);
    for(auto d:data) emplace(d.first, d.second, false);
  }
  void emplace(Key k, Val v, bool g=true){
    assert(k!=null_key);
    uint32_t h = f(k) & mod;
    while(true){
      if(key_table[h]!=null_key){
        if(key_table[h]==k) return;
        h = (h + 1) & mod;
      }else{
        if(g) data.push_back({k, v});
        key_table[h] = k;
        val_table[h] = v;
        if(float(data.size())>load_factor*float(table_size)){
          expand_table();
        }
        return;
      }
    }
  }
  bool contain(Key k){
    assert(k!=null_key);
    unsigned h = f(k) & mod;
    while(true){
      if(key_table[h]==null_key) return false;
      if(key_table[h]==k) return true;
      h = (h + 1) & mod;
    }
  }
  Val at(Key k){
    assert(k!=null_key);
    unsigned h = f(k) & mod;
    while(true){
      assert(key_table[h]!=null_key);
      if(key_table[h]==k) return val_table[h];
      h = (h + 1) & mod;
    }
  }
  Val &at_ref(Key k){
    assert(k!=null_key);
    unsigned h = f(k) & mod;
    while(true){
      assert(key_table[h]!=null_key);
      if(key_table[h]==k) return val_table[h];
      h = (h + 1) & mod;
    }
  }
};


template<typename Key>
struct hashmultiset{
  float load_factor = 0.8;
  int table_size = 16;
  int mod = 15;
  Key null_key;
  vector<Key> key_table;
  vector<int> idx_table;
  vector<pair<Key, int>> data;
  function<uint32_t(Key)> f = std::hash<uint32_t>();

  hashmultiset():
    null_key(std::numeric_limits<Key>::max()),
    key_table(table_size, null_key), idx_table(table_size){}
  int size(){
    return data.size();
  }
  void expand_table(){
    table_size *= 2;
    mod = table_size - 1;
    key_table.resize(table_size);
    idx_table.resize(table_size);
    fill(key_table.begin(), key_table.end(), null_key);
    for(int i=0;i<data.size();i++) insert(data[i].first, i);
  }
  void insert(Key k, int idx){
    assert(k!=null_key);
    uint32_t h = f(k) & mod;
    while(true){
      if(key_table[h]!=null_key){
        if(key_table[h]==k) return;
        h = (h + 1) & mod;
      }else{
        key_table[h] = k;
        idx_table[h]= idx;
        if(float(data.size())>load_factor*float(table_size)){
          expand_table();
        }
        return;
      }
    }
  }
  void insert(Key k){
    assert(k!=null_key);
    uint32_t h = f(k) & mod;
    while(true){
      if(key_table[h]!=null_key){
        if(key_table[h]==k){
          data[idx_table[h]].second++;
          return;
        }
        h = (h + 1) & mod;
      }else{
        int idx = data.size();
        data.push_back({k, 1});
        key_table[h] = k;
        idx_table[h] = idx;
        if(float(data.size())>load_factor*float(table_size)){
          expand_table();
        }
        return;
      }
    }
  }
  int count(Key k){
    assert(k!=null_key);
    unsigned h = f(k) & mod;
    while(true){
      if(key_table[h]==null_key) return 0;
      if(key_table[h]==k) return data[idx_table[h]].second;
      h = (h + 1) & mod;
    }
  }
};

int main(){
  ll n, m;scanf("%lld %lld", &n, &m);
  //hashmultiset<ll> st;
  map<ll, int> mp;
  for(int i=0;i<n;i++){
    ll a;scanf("%lld", &a);
    mp[a]++;
  }
  for(int i=0;i<m;i++){
    ll a;scanf("%lld", &a);
    if(i==m-1) printf("%d\n", mp[a]);
    else printf("%d ", mp[a]);
  }
}
0