Pagini recente » Cod sursa (job #3126346) | Cod sursa (job #464198) | Cod sursa (job #2330636) | Cod sursa (job #2254992) | Cod sursa (job #605609)
Cod sursa(job #605609)
#include <stdio.h>
#include <vector>
using namespace std;
int n;
vector<long> vec[99999];
inline int hash(int val)
{
return val % 10000;
}
inline void add(int val)
{
int poz = hash(val);
vec[poz].push_back(val);
}
vector<long>::iterator find(int val)
{
int poz = hash(val);
vector<long>::iterator it;
for (it = vec[poz].begin(); it != vec[poz].end(); ++it)
{
if (*it == val)
{
return it;
}
}
return vec[poz].end();
}
inline void del(int val)
{
vector<long>::iterator it = find(val);
int poz = hash(val);
if (it != vec[poz].end())
vec[poz].erase(it);
}
void findd(int val)
{
int poz = hash(val);
vector<long>::iterator it = find(val);
if (it != vec[poz].end())
printf("%d\n", 1);
else
printf("%d\n", 0);
}
int main()
{
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "w", stdout);
scanf("%d", &n);
int op, param;
for (int i = 0; i < n; ++i)
{
scanf("%d%d", &op, ¶m);
switch(op)
{
case(1): add(param); break;
case(2): del(param); break;
case(3): findd(param); break;
}
}
return 0;
}