1 namespace Hash 2 { 3 const ll N=50000; 4 const ll H=999979; 5 struct adj 6 { 7 ll nxt,v,num,val; 8 }e[N]; 9 ll head[H],ecnt=0; 10 void init() 11 { 12 ecnt=0; 13 memset(head,0,sizeof(head)); 14 } 15 void insert(ll x,ll val) 16 { 17 ll org=x; 18 x%=H; 19 for (int i=head[x];i;i=e[i].nxt) 20 { 21 if (e[i].num==org) 22 { 23 e[i].val=val; 24 return ; 25 } 26 } 27 e[++ecnt].num=org; 28 e[ecnt].val=val; 29 e[ecnt].nxt=head[x]; 30 head[x]=ecnt; 31 } 32 ll query(ll x) 33 { 34 ll org=x; 35 x%=H; 36 for (int i=head[x];i;i=e[i].nxt) 37 if (e[i].num==org) return e[i].val; 38 return -1; 39 } 40 }