結果

問題 No.3016 unordered_mapなるたけ落とすマン
ユーザー tonegawatonegawa
提出日時 2020-11-25 04:01:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 1,000 ms
コード長 3,799 bytes
コンパイル時間 1,870 ms
コンパイル使用メモリ 133,036 KB
実行使用メモリ 10,196 KB
最終ジャッジ日時 2023-10-01 01:36:35
合計ジャッジ時間 7,223 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 54 ms
9,940 KB
testcase_04 AC 62 ms
10,168 KB
testcase_05 AC 60 ms
9,940 KB
testcase_06 AC 63 ms
10,008 KB
testcase_07 AC 60 ms
10,028 KB
testcase_08 AC 61 ms
10,000 KB
testcase_09 AC 61 ms
9,896 KB
testcase_10 AC 58 ms
10,196 KB
testcase_11 AC 59 ms
9,968 KB
testcase_12 AC 59 ms
9,840 KB
testcase_13 AC 58 ms
9,840 KB
testcase_14 AC 59 ms
10,180 KB
testcase_15 AC 58 ms
10,156 KB
testcase_16 AC 61 ms
9,952 KB
testcase_17 AC 58 ms
9,840 KB
testcase_18 AC 58 ms
9,952 KB
testcase_19 AC 60 ms
9,900 KB
testcase_20 AC 56 ms
9,952 KB
testcase_21 AC 58 ms
10,024 KB
testcase_22 AC 58 ms
10,000 KB
testcase_23 AC 57 ms
9,948 KB
testcase_24 AC 57 ms
10,028 KB
testcase_25 AC 57 ms
10,008 KB
testcase_26 AC 57 ms
9,896 KB
testcase_27 AC 56 ms
10,176 KB
testcase_28 AC 54 ms
9,884 KB
testcase_29 AC 56 ms
10,180 KB
testcase_30 AC 56 ms
9,900 KB
testcase_31 AC 56 ms
9,952 KB
testcase_32 AC 55 ms
10,144 KB
testcase_33 AC 56 ms
9,844 KB
testcase_34 AC 56 ms
9,960 KB
testcase_35 AC 54 ms
9,996 KB
testcase_36 AC 55 ms
9,996 KB
testcase_37 AC 54 ms
10,000 KB
testcase_38 AC 54 ms
9,696 KB
testcase_39 AC 54 ms
9,576 KB
testcase_40 AC 54 ms
9,696 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 6 ms
4,380 KB
testcase_45 AC 6 ms
4,380 KB
testcase_46 AC 5 ms
4,376 KB
testcase_47 AC 40 ms
5,264 KB
testcase_48 AC 47 ms
6,152 KB
testcase_49 AC 45 ms
6,108 KB
testcase_50 AC 42 ms
4,376 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>
#include <random>
#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, typename Val>
struct hashmultimap{
private:
  float load_factor = 0.8;
  int table_size = 16;
  int mod = 15;
  Key null_key;
  uint32_t mask;
  int valid_size;
  int valid_type;
  vector<int> idx_table;
  vector<Key> key_data;
  vector<vector<Val>> val_data;
  function<uint32_t(Key)> f = std::hash<uint32_t>();
  void expand_table(){
    table_size *= 2;
    mod = table_size - 1;
    idx_table.resize(table_size);
    fill(idx_table.begin(), idx_table.end(), -1);
    for(int i=0;i<key_data.size();i++){
      if(key_data[i]==null_key) continue;
      inner_emplace(i);
    }
  }
  void inner_emplace(int idx){
    Key k = key_data[idx];
    uint32_t h = f(k^mask) & mod;
    while(true){
      if(idx_table[h]==-1){
        idx_table[h] = idx;
        return;
      }
      h = (h + 1) & mod;
    }
  }
public:
  hashmultimap():
    null_key(std::numeric_limits<Key>::max()),
    mask(random_device()()), valid_size(0), valid_type(0),
    idx_table(table_size, -1){}

  //データ数の総和
  int size(){
    return valid_size;
  }
  //データの種類数
  int type(){
    return valid_type;
  }
  //挿入
  void emplace(Key k, Val v){
    assert(k!=null_key);
    uint32_t h = f(k^mask) & mod;
    while(true){
      int idx = idx_table[h];
      if(idx!=-1){
        if(key_data[idx]==k){
          val_data[idx].push_back(v);
          valid_size++;
          return;
        }
        h = (h + 1) & mod;
      }else{
        int m = key_data.size();
        key_data.push_back(k);
        val_data.push_back(vector<Val>());
        val_data[m].push_back(v);
        idx_table[h] = m;
        valid_type++;
        valid_size++;
        if(float(key_data.size())>load_factor*float(table_size)){
          expand_table();
        }
        return;
      }
    }
  }
  //Key kの値を全て削除
  void erase_all(Key k){
    assert(k!=null_key);
    uint32_t h = f(k^mask) & mod;
    while(true){
      int idx = idx_table[h];
      if(idx==-1) return;
      if(key_data[idx]==k){
        key_data[idx].first = null_key;
        valid_size -= int(val_data[idx].size());
        valid_type--;
        val_data[idx].clear();
        return;
      }
      h = (h + 1) & mod;
    }
  }
  //Key kに含まれている要素数
  int size(Key k){
    assert(k!=null_key);
    uint32_t h = f(k^mask) & mod;
    while(true){
      int idx = idx_table[h];
      if(idx==-1) return 0;
      if(key_data[idx]==k) return int(val_data[idx].size());
      h = (h + 1) & mod;
    }
  }
  //Key kの要素たちを受け取る(計算量に注意)
  vector<Val> at(Key k){
    assert(k!=null_key);
    uint32_t h = f(k^mask) & mod;
    while(true){
      int idx = idx_table[h];
      if(idx==-1) return vector<Val>(0);
      if(key_data[idx]==k) {
        return val_data[idx];
      }
      h = (h + 1) & mod;
    }
  }
};

int main(){
  ll n, m;scanf("%lld %lld", &n, &m);
  hashmultimap<ll, int> mp;
  for(int i=0;i<n;i++){
    ll a;scanf("%lld", &a);
    mp.emplace(a, 1);
  }
  for(int i=0;i<m;i++){
    ll a;scanf("%lld", &a);
    if(i==m-1) printf("%d\n", mp.size(a));
    else printf("%d ", mp.size(a));
  }
}
0