Pagini recente » Cod sursa (job #1964286) | Cod sursa (job #2252713) | Cod sursa (job #353762) | Cod sursa (job #2707791) | Cod sursa (job #1262682)
#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 y)
{
int poz;
poz = x%p;
swap(L[poz][y],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 i;
return -1;
}
int main()
{
int i,x,y,op;
f>>n;
for(i=1;i<=n;i++)
{
f>>op>>x;
if(op == 1)
{
if(Hash(x) == -1) Add_hash(x);
}
else if(op == 2)
{
y= Hash(x);
if(y != -1)
Del_hash(x,y);
}
else
if (op == 3)
{
y=Hash(x);
if(y == -1) g<<0<<"\n";
else g<<1<<"\n";
}
}
return 0;
}