結果

問題 No.3016 unordered_mapなるたけ落とすマン
ユーザー TlapesiumTlapesium
提出日時 2020-08-16 19:44:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 1,000 ms
コード長 3,426 bytes
コンパイル時間 3,190 ms
コンパイル使用メモリ 221,316 KB
実行使用メモリ 9,548 KB
最終ジャッジ日時 2024-04-27 05:00:02
合計ジャッジ時間 7,572 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
9,336 KB
testcase_01 AC 5 ms
9,284 KB
testcase_02 AC 4 ms
9,256 KB
testcase_03 AC 45 ms
9,256 KB
testcase_04 AC 49 ms
9,416 KB
testcase_05 AC 47 ms
9,440 KB
testcase_06 AC 44 ms
9,376 KB
testcase_07 AC 42 ms
9,288 KB
testcase_08 AC 48 ms
9,288 KB
testcase_09 AC 47 ms
9,384 KB
testcase_10 AC 47 ms
9,332 KB
testcase_11 AC 47 ms
9,344 KB
testcase_12 AC 46 ms
9,200 KB
testcase_13 AC 44 ms
9,328 KB
testcase_14 AC 46 ms
9,196 KB
testcase_15 AC 40 ms
9,368 KB
testcase_16 AC 46 ms
9,408 KB
testcase_17 AC 42 ms
9,364 KB
testcase_18 AC 47 ms
9,372 KB
testcase_19 AC 43 ms
9,436 KB
testcase_20 AC 40 ms
9,424 KB
testcase_21 AC 40 ms
9,372 KB
testcase_22 AC 41 ms
9,260 KB
testcase_23 AC 39 ms
9,336 KB
testcase_24 AC 39 ms
9,376 KB
testcase_25 AC 44 ms
9,348 KB
testcase_26 AC 43 ms
9,364 KB
testcase_27 AC 44 ms
9,464 KB
testcase_28 AC 38 ms
9,404 KB
testcase_29 AC 42 ms
9,292 KB
testcase_30 AC 38 ms
9,256 KB
testcase_31 AC 41 ms
9,368 KB
testcase_32 AC 43 ms
9,412 KB
testcase_33 AC 43 ms
9,200 KB
testcase_34 AC 42 ms
9,464 KB
testcase_35 AC 42 ms
9,388 KB
testcase_36 AC 42 ms
9,368 KB
testcase_37 AC 42 ms
9,256 KB
testcase_38 AC 43 ms
9,388 KB
testcase_39 AC 39 ms
9,440 KB
testcase_40 AC 36 ms
9,448 KB
testcase_41 AC 5 ms
9,368 KB
testcase_42 AC 5 ms
9,316 KB
testcase_43 AC 5 ms
9,392 KB
testcase_44 AC 7 ms
9,436 KB
testcase_45 AC 7 ms
9,348 KB
testcase_46 AC 7 ms
9,384 KB
testcase_47 AC 36 ms
9,360 KB
testcase_48 AC 35 ms
9,412 KB
testcase_49 AC 35 ms
9,548 KB
testcase_50 AC 40 ms
9,196 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) {
		bsize = nextsize;
		msize = bsize * 0.7;
		dsize = 0;
		tombsize = 0;
		auto tmp = move(varray);
		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;
	}

	const valtype& operator[] (keytype key) const {
		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(200000);
	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