Pagini recente » Cod sursa (job #1532881) | Cod sursa (job #191140) | Cod sursa (job #1256706) | Cod sursa (job #581366) | Cod sursa (job #2221389)
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#define BIGPRIMENUMBER 138257
using namespace std;
class Hash
{
vector<int> lists[BIGPRIMENUMBER];
public:
bool search(int x, int &i)
{
int indice = x % BIGPRIMENUMBER;
for(i = 0; i < lists[indice].size(); ++i)
{
if(lists[indice][i] == x)
return true;
}
return false;
}
bool search(int x)
{
int indice = x % BIGPRIMENUMBER;
for(int i = 0; i < lists[indice].size(); ++i)
{
if(lists[indice][i] == x)
return true;
}
return false;
}
void insert(int x)
{
if(!search(x))
{
int indice = x % BIGPRIMENUMBER;
lists[indice].push_back(x);
}
}
void remove(int x)
{
int indice, listIndice = 0;
if(search(x, listIndice))
{
int indice = x % BIGPRIMENUMBER;
lists[indice].erase(lists[indice].begin() + listIndice);
}
}
};
int main()
{
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "w", stdout);
int n;
Hash h;
scanf("%d", &n);
for(int i = 0; i < n; ++i)
{
int op, nr;
scanf("%d", &op);
scanf("%d", &nr);
switch(op)
{
case 1:
h.insert(nr);
break;
case 2:
h.remove(nr);
break;
case 3:
printf("%d\n", (int)h.search(nr));
break;
default:
break;
}
}
return 0;
}