Pagini recente » Cod sursa (job #1501869) | Cod sursa (job #1125869) | Monitorul de evaluare | Istoria paginii runda/cnrvxa1 | Cod sursa (job #1211745)
#include <iostream>
#include <fstream>
#include <vector>
#include <time.h>
#include <stdlib.h>
#define lth 25999
using namespace std;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
int n,r;
vector <int> hsh[50000];
void initKey()
{
r = rand() % 1000;
}
int getKey(int a)
{
return (a + r) % lth;
}
bool find(int b)
{
int k = getKey(b);
for(int i = 0; i < hsh[k].size(); i++)
{
if(hsh[k][i] == b)
{
return true;
}
}
return false;
}
void insert(int b)
{
if(find(b) == false)
{
int key = getKey(b);
hsh[key].push_back(b);
}
}
void remove(int b)
{
int k = getKey(b);
if(find(b) == false)
{
return;
}
for(int i = 0; i < hsh[k].size(); i++)
{
if(hsh[k][i] == b)
{
hsh[k].erase(hsh[k].begin() + i);
}
}
}
void read()
{
int a,b;
in>>n;
for(int i = 1; i <= n; i++)
{
in >> a >> b;
if(a == 1)
{
insert(b);
}
else if(a == 2)
{
remove(b);
}
else if(a == 3)
{
if(find(b) == true)
{
out<<"1\n";
}
else
{
out<<"0\n";
}
}
}
}
int main()
{
read();
return 0;
}