Pagini recente » Cod sursa (job #2612272) | Cod sursa (job #2979099) | Cod sursa (job #2845492) | Cod sursa (job #3181157) | Cod sursa (job #622901)
Cod sursa(job #622901)
#include <stdio.h>
#include <vector>
#define m 666013
using namespace std;
int n;
vector <int> ht[m];
inline vector<int>::iterator poz(int x, int i)
{
vector <int>::iterator index;
for (index = ht[i].begin();index!=ht[i].end();index++)
{
if (*index == x)
return index;
}
return ht[i].end();
}
inline void add(int x)
{
int i=x%m;
vector <int>::iterator index = poz(x,i);
if (index == ht[i].end())
ht[i].push_back(x);
}
inline void del(int x)
{
int i=x%m;
vector <int>::iterator index = poz(x,i);
if (index != ht[i].end())
ht[i].erase(index);
}
inline int search(int x)
{
int i=x%m;
vector <int>::iterator index = poz(x,i);
if (index != ht[i].end())
return 1;
return 0;
}
int main()
{
int i,c,x;
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
scanf("%d",&n);
for (i=0;i<n;i++)
{
scanf("%d %d",&c,&x);
if (c==1) //add x to table
{
add(x);
}
if (c==2) //delete x from table
{
del(x);
}
if (c==3) //is x in table ?
{
printf("%d\n",search(x));
}
}
return 0;
}