Pagini recente » Cod sursa (job #566296) | Cod sursa (job #1663671) | Cod sursa (job #3163255) | Cod sursa (job #1166625) | Cod sursa (job #1262111)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
vector <int> L[1004];
int n;
int p = 1003;
void Add_hash(int x)
{
int poz;
poz = x%p;
L[poz].push_back(x);
}
void Del_hash(int x)
{
int poz;
poz = x%p;
swap(L[poz][x],L[poz][L[poz].size()-1]);
L[poz].pop_back();
}
int Hash(int x)
{
int poz,i;
poz = x%p;
for(i=0;i<L[poz].size();i++)
if(L[poz][i] == x )
return 1;
return 0;
}
int main()
{
int i,x,op;
f>>n;
for(i=1;i<=n;i++)
{
f>>op>>x;
if(op == 1)
{
if(Hash(x) == 0) Add_hash(x);
// cout<<"A";
}
else if(op == 2)
{
if(Hash(x) == 1) Del_hash(x);
// cout<<"D";
}
else if (op == 3) cout<<Hash(x)<<"\n";
}
return 0;
}