結果

問題 No.3016 unordered_mapなるたけ落とすマン
ユーザー TlapesiumTlapesium
提出日時 2020-08-16 18:47:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 1,000 ms
コード長 3,042 bytes
コンパイル時間 3,316 ms
コンパイル使用メモリ 222,972 KB
実行使用メモリ 15,580 KB
最終ジャッジ日時 2024-04-27 04:59:59
合計ジャッジ時間 7,798 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,812 KB
testcase_01 AC 4 ms
6,940 KB
testcase_02 AC 4 ms
6,940 KB
testcase_03 AC 48 ms
15,540 KB
testcase_04 AC 50 ms
15,480 KB
testcase_05 AC 50 ms
15,536 KB
testcase_06 AC 51 ms
15,424 KB
testcase_07 AC 50 ms
15,452 KB
testcase_08 AC 52 ms
15,532 KB
testcase_09 AC 48 ms
15,524 KB
testcase_10 AC 52 ms
15,428 KB
testcase_11 AC 51 ms
15,424 KB
testcase_12 AC 51 ms
15,544 KB
testcase_13 AC 48 ms
15,532 KB
testcase_14 AC 50 ms
15,492 KB
testcase_15 AC 49 ms
15,424 KB
testcase_16 AC 51 ms
15,572 KB
testcase_17 AC 48 ms
15,524 KB
testcase_18 AC 49 ms
15,560 KB
testcase_19 AC 46 ms
15,580 KB
testcase_20 AC 45 ms
15,448 KB
testcase_21 AC 48 ms
15,560 KB
testcase_22 AC 48 ms
15,356 KB
testcase_23 AC 47 ms
15,576 KB
testcase_24 AC 47 ms
15,484 KB
testcase_25 AC 46 ms
15,504 KB
testcase_26 AC 48 ms
15,532 KB
testcase_27 AC 47 ms
15,368 KB
testcase_28 AC 46 ms
15,520 KB
testcase_29 AC 44 ms
15,424 KB
testcase_30 AC 46 ms
15,420 KB
testcase_31 AC 47 ms
15,364 KB
testcase_32 AC 45 ms
15,424 KB
testcase_33 AC 45 ms
15,544 KB
testcase_34 AC 46 ms
15,360 KB
testcase_35 AC 44 ms
15,504 KB
testcase_36 AC 43 ms
15,472 KB
testcase_37 AC 44 ms
15,480 KB
testcase_38 AC 44 ms
15,500 KB
testcase_39 AC 45 ms
15,564 KB
testcase_40 AC 43 ms
15,528 KB
testcase_41 AC 3 ms
6,948 KB
testcase_42 AC 3 ms
6,940 KB
testcase_43 AC 4 ms
6,944 KB
testcase_44 AC 6 ms
6,944 KB
testcase_45 AC 5 ms
6,944 KB
testcase_46 AC 6 ms
6,944 KB
testcase_47 AC 33 ms
6,940 KB
testcase_48 AC 33 ms
6,940 KB
testcase_49 AC 35 ms
6,940 KB
testcase_50 AC 38 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
//#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")
#define io_init cin.tie(0);ios::sync_with_stdio(0);cout<<setprecision(10)
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

template<typename keytype, typename valtype, typename Hasher = hash<keytype>, typename isEqual = equal_to<keytype>>
struct HashMap {
	int bsize; // アドレスの数
	int msize; // msize > dsize のときリハッシュする
	int dsize = 0; // データの数
	int tombsize = 0; // 削除済みデータの数

	struct container {
		// 0 -> empty  1 -> used  2 -> deleted
		int used = 0;
		pair<keytype, valtype> data;
	};

	vector<container> varray;

	HashMap(int BucketSize = 100000) {
		bsize = 1 << (32 - __builtin_clz(BucketSize));
		msize = bsize * 0.7;
		varray = vector<container>(bsize);
	}

	void resize(int nextsize) {
		auto tmp = varray;
		bsize = nextsize;
		msize = bsize * 0.7;
		dsize = 0;
		tombsize = 0;
		varray = vector<container>(bsize);
		for (int i = 0; i < tmp.size(); i++) {
			if (tmp[i].used != 1)continue;
			insert(tmp[i].data.first, tmp[i].data.second);
		}
	}

	valtype& insert(const keytype& a, const valtype& b) {
		if (dsize + 1 > msize)resize(bsize << 1);
		ull Hash = Hasher()(a);
		while (varray[Hash & (bsize - 1)].used != 0) {
			if (isEqual()(varray[Hash & (bsize - 1)].data.first, a)) return varray[Hash & (bsize - 1)].data.second;
			Hash++;
		}
		varray[Hash & (bsize - 1)] = { 1,{a,b} };
		dsize++;
		return varray[Hash & (bsize - 1)].data.second;
	}

	void erase(const keytype& key) {
		ull Hash = Hasher()(key);
		while (varray[Hash & (bsize - 1)].used && !isEqual()(varray[Hash & (bsize - 1)].data.first, key)) Hash++;
		if (varray[Hash & (bsize - 1)].used != 1 || !isEqual()(varray[Hash & (bsize - 1)].data.first, key)) throw "Not Found";
		varray[Hash & (bsize - 1)].used = 2;
		tombsize++;
	}

	valtype& at(const keytype& key) {
		ull Hash = Hasher()(key);
		while (varray[Hash & (bsize - 1)].used && !isEqual()(varray[Hash & (bsize - 1)].data.first, key)) Hash++;
		if (varray[Hash & (bsize - 1)].used != 1 || !isEqual()(varray[Hash & (bsize - 1)].data.first, key)) throw "Not Found";
		return varray[Hash & (bsize - 1)].data.second;
	}

	valtype& operator[] (keytype key) {
		ull Hash = Hasher()(key);
		while (varray[Hash & (bsize - 1)].used && !isEqual()(varray[Hash & (bsize - 1)].data.first, key))  Hash++;
		if (varray[Hash & (bsize - 1)].used != 1 || !isEqual()(varray[Hash & (bsize - 1)].data.first, key))return insert(key, valtype());
		return varray[Hash & (bsize - 1)].data.second;
	}
};

int main() {
	io_init;
	int N, M;
	cin >> N >> M;
	HashMap<ll, int> hm;
	for (int i = 0; i < N; i++) {
		ll tmp;
		cin >> tmp;
		hm[tmp]++;
	}
	for (int i = 0; i < M; i++) {
		ll tmp;
		cin >> tmp;
		cout << hm[tmp] << (i == M ? "\n" : " ");
	}
}
0