Pagini recente » Cod sursa (job #1095191) | Cod sursa (job #592222) | Cod sursa (job #2628777) | Cod sursa (job #2187017) | Cod sursa (job #629379)
Cod sursa(job #629379)
#include <fstream>
#include <vector>
#define p 666013
using namespace std;
vector<int> h[p];
void adauga(long x)
{
vector<int>::iterator it=h[x%p].begin();
while ((it!=h[x%p].end())&&((*it)!=x))
it++;
if ((it==h[x%p].end())||(*it)!=x)
h[x%p].push_back(x);
}//adauga
void sterge(long x)
{
unsigned long i=0;
while ((i<h[x%p].size())&&(h[x%p][i]!=x))
i++;
if ((i<h[x%p].size())&&(h[x%p][i]==x))
{
h[x%p][i]=h[x%p][h[x%p].size()];
h[x%p].pop_back();
}//if
}//sterge
int cauta(long x)
{
vector<int>::iterator it=h[x%p].begin();
while ((it!=h[x%p].end())&&((*it)!=x))
it++;
if ((it!=h[x%p].end())&&(*it)==x)
return 1;
return 0;
}//cauta
int main()
{
long n, o, x;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
fin>>n;
for (long i=0; i<n; i++)
{
fin>>o>>x;
if (o==1)
adauga(x);
if (o==2)
sterge(x);
if (o==3)
fout<<cauta(x)<<"\n";
}//for i
return 0;
}//main