結果

問題 No.3016 unordered_mapなるたけ落とすマン
ユーザー Ryuhei MoriRyuhei Mori
提出日時 2020-05-23 17:24:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 1,000 ms
コード長 2,277 bytes
コンパイル時間 511 ms
コンパイル使用メモリ 57,080 KB
実行使用メモリ 8,960 KB
最終ジャッジ日時 2024-04-17 04:00:52
合計ジャッジ時間 4,391 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 17 ms
8,320 KB
testcase_04 AC 19 ms
8,704 KB
testcase_05 AC 19 ms
8,576 KB
testcase_06 AC 20 ms
8,704 KB
testcase_07 AC 20 ms
8,832 KB
testcase_08 AC 20 ms
8,960 KB
testcase_09 AC 19 ms
8,448 KB
testcase_10 AC 19 ms
8,448 KB
testcase_11 AC 19 ms
8,576 KB
testcase_12 AC 19 ms
8,448 KB
testcase_13 AC 18 ms
8,576 KB
testcase_14 AC 18 ms
8,448 KB
testcase_15 AC 19 ms
8,448 KB
testcase_16 AC 18 ms
8,448 KB
testcase_17 AC 19 ms
8,320 KB
testcase_18 AC 18 ms
8,448 KB
testcase_19 AC 18 ms
8,192 KB
testcase_20 AC 18 ms
8,064 KB
testcase_21 AC 18 ms
8,192 KB
testcase_22 AC 19 ms
8,448 KB
testcase_23 AC 18 ms
8,064 KB
testcase_24 AC 18 ms
8,192 KB
testcase_25 AC 18 ms
8,064 KB
testcase_26 AC 19 ms
8,192 KB
testcase_27 AC 17 ms
8,064 KB
testcase_28 AC 18 ms
8,448 KB
testcase_29 AC 17 ms
8,064 KB
testcase_30 AC 18 ms
8,192 KB
testcase_31 AC 17 ms
7,936 KB
testcase_32 AC 18 ms
8,064 KB
testcase_33 AC 18 ms
8,192 KB
testcase_34 AC 17 ms
7,808 KB
testcase_35 AC 17 ms
7,936 KB
testcase_36 AC 18 ms
8,184 KB
testcase_37 AC 17 ms
7,936 KB
testcase_38 AC 18 ms
7,808 KB
testcase_39 AC 16 ms
7,808 KB
testcase_40 AC 16 ms
7,552 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 2 ms
5,376 KB
testcase_44 AC 3 ms
5,376 KB
testcase_45 AC 4 ms
5,376 KB
testcase_46 AC 3 ms
5,376 KB
testcase_47 AC 14 ms
7,296 KB
testcase_48 AC 16 ms
7,552 KB
testcase_49 AC 15 ms
7,424 KB
testcase_50 AC 11 ms
7,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <array>
#include <vector>
#include <unistd.h>

struct IO {
  static const int bufsize=1<<24;
  char ibuf[bufsize], obuf[bufsize];
  char *ip, *op;
  IO(): ip(ibuf), op(obuf) { for(int t = 0, k = 0; (k = read(STDIN_FILENO, ibuf+t, sizeof(ibuf)-t)) > 0; t+=k); }
  ~IO(){ for(int t = 0, k = 0; (k = write(STDOUT_FILENO, obuf+t, op-obuf-t)) > 0; t+=k); }
  long long scan_int(){
    long long x=0;
    bool neg=false;
    for(;*ip<'+';ip++) ;
    if(*ip=='-'){ neg=true; ip++;}
    else if(*ip=='+') ip++;
    for(;*ip>='0';ip++) x = 10*x+*ip-'0';
    if(neg) x = -x;
    return x;
  }
  void put_int(long long x, char c=0){
    static char tmp[20];
    if(x==0) *op++ = '0';
    else {
      int i;
      if(x<0){
        *op++ = '-';
        x = -x;
      }
      for(i=0; x; i++){
        tmp[i] = x % 10;
        x /= 10;
      }
      for(i--; i>=0; i--)
        *op++ = tmp[i]+'0';
    }
    if(c) *op++ = c;
  }
  void put_double(double x, char c=0){
    unsigned y;
    const int mask = (1<<24) - 1;
    put_int(x);
    *op++ = '.';
    x = x - (int) x;
    if(x < 0) x = -x;
    y = x * (1<<24);

    for(int i=0;i<7;i++){
      y *= 10;
      *op++ = '0' + (y>>24);
      y &= mask;
    }
    if(c) *op++ = c;
  }
  inline char scan_char(){ return *ip++; }
  inline void put_char(char c){ *op++ = c; }
  inline char *scan_string(){ char *s = ip; while(*ip!='\n'&&*ip!=' ') ip++; *ip++='\0'; return s;}
  inline void put_string(const char *s, char c=0){ while(*s) *op++=*s++; if(c) *op++=c;}
} io;


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

template <typename T, int n, T z = T()>
class hash_map {
  std::array<std::vector<std::pair<u64, T> >, 1<<(n-4)> v;

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

  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, z);
    return v[i].back().second;
  }
};

int n, m;

int main(){
  n = io.scan_int();
  m = io.scan_int();

  hash_map<u64, 17> h;
  for(int i = 0; i < n; i++){
    u64 a = io.scan_int();
    ++h[a];
  }
  for(int i = 0; i < m; i++){
    u64 a = io.scan_int();
    io.put_int(h[a], " \n"[i == m-1]);
  }
  return 0;
}
0