Pagini recente » Cod sursa (job #2747982) | Cod sursa (job #2628780) | Cod sursa (job #2185897) | Cod sursa (job #2709741) | Cod sursa (job #1262679)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
vector <int> L[100003];
int n;
int p = 100003;
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) g<<Hash(x)<<"\n";
}
return 0;
}