Pagini recente » Cod sursa (job #2505770) | Cod sursa (job #895589) | Cod sursa (job #1674603) | Cod sursa (job #1947115) | Cod sursa (job #2909912)
#include <iostream>
#include<vector>
using namespace std;
const int m=666013;
vector<int>table[m];
int hashfind(int x)
{
int id=x%m;
for(int i=0; i<table[id].size(); i++)
if (x==table[id][i])return 1;
return 0;
}
void hashinsert(int x)
{
if(hashfind(x)==0) {
int id=x%m;
table[id].push_back(x);
}
}
void hashdelete(int x)
{
if(hashfind(x)==1){
int id=x%m;
for(int i=0; i<table[id].size(); i++)
if(x==table[id][i]){swap(table[id][i], table[id][table[id].size()-1]);
table[id].pop_back();}
}
}
int main()
{
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "w", stdout);
int N;
scanf("%d", &N);
for(;N-->0;)
{
int op,x;
scanf("%d%d", &op, &x);
if(op==1)hashinsert(x);
if(op==2)hashdelete(x);
if(op==3)printf("%d\n",hashfind(x));
}
}