Pagini recente » Cod sursa (job #359529) | Cod sursa (job #1690146) | Istoria paginii utilizator/deiviid | Cod sursa (job #2479596) | Cod sursa (job #2004494)
#include <cstdio>
#include <vector>
#include <algorithm>
#define DIM 666013
using namespace std;
char buffer[DIM];
int poz = DIM - 1;
void Scan(int &A)
{
A = 0;
while('0' > buffer[poz] || buffer[poz] >'9')
if(++poz == DIM) fread(buffer,1,DIM,stdin),poz = 0;
while('0' <= buffer[poz] && buffer[poz] <= '9')
{
A = A * 10 + buffer[poz] - 48;
if(++poz == DIM) fread(buffer,1,DIM,stdin),poz = 0;
}
}
class Hash{
private:
vector<int> range[DIM];
int key;
public:
int Search(int value){
key = value % DIM;
for(vector<int>::iterator it = range[key].begin(); it != range[key].end(); ++it)
if(*it == value) return 1;
return 0;
}
void Insert(int value){
key = value % DIM;
if(!Search(value))
range[key].push_back(value);
}
void Delete(int value){
int key = value % DIM;
for(vector<int>::iterator it = range[key].begin();it != range[key].end(); ++it)
if(*it == value)
{
range[key].erase(it);
return;
}
}
}Hash_Table;
int main()
{
freopen("hashuri.in","r",stdin);
freopen("hashuri.out","w",stdout);
int N,op,x;
Scan(N);
for(int i = 1; i <= N; ++i)
{
Scan(op);Scan(x);
if(op == 1)
Hash_Table.Insert(x);
else
if(op == 2)
Hash_Table.Delete(x);
else
printf("%d\n",Hash_Table.Search(x));
}
return 0;
}