Pagini recente » Cod sursa (job #2440323) | Cod sursa (job #323356) | Cod sursa (job #627463) | Cod sursa (job #258474) | Cod sursa (job #808602)
Cod sursa(job #808602)
#include <iostream>
#include<stdio.h>
#include <vector>
#define rest 666013
using namespace std;
vector <long> hash[rest];
void insert (long long x)
{
int i,k;
k=x%rest;
for(i=0;i<hash[k].size();i++)
{
if (hash[k][i]==x) return;
}
hash[k].push_back(x);
}
void erase(long long x)
{
int i,k;
k=x%rest;
for(i=0;i<hash[k].size();i++)
{
if (hash[k][i]==x) {
hash[k][i]=hash[k].back();
hash[k].pop_back();
return;
}
}
}
int count(long long x)
{
int i,k;
k=x%rest;
for(i=0;i<hash[k].size();i++)
{
if (hash[k][i]==x) return 1;
else return 0;
}
}
int main()
{
int op;
long long x;
long n,i;
FILE*f,*g;
f=fopen("hashuri.in","r");
freopen("hashuri.txt","w",stdout);
fscanf(f,"%ld",&n);
for(i=1;i<=n;i++)
{
fscanf(f,"%d",&op);
fscanf(f,"%lld",&x);
switch(op)
{
case 1: {insert(x); break;}
case 2: {erase(x); break;}
case 3: {printf("%d\n",count(x)); break;}
}
}
return 0;
}