Hash表

完全顶替map

const int S=10000019;
struct HashMap{	
	std::vector<int>head,nxt;
	struct node{
		int x,v;
	};std::vector<node>to;
	inline void clear(){
		head.resize(S+3,-1);
	}
	HashMap(){
		clear();
	}
	inline int & operator[](int x){
		int u=x%S;
		for(int i=head[u];~i;i=nxt[i]){
			if(to[i].x==x){
				return to[i].v;
			}
		}
		nxt.push_back(head[u]);
		head[u]=to.size();
		to.push_back({x,0});
		return to[to.size()-1].v;
	}
};
posted @ 2022-02-24 09:15  cbdsopa  阅读(35)  评论(0)    收藏  举报