Pagini recente » Cod sursa (job #2837182) | Profil volosciucedmond | Cod sursa (job #2627449) | Cod sursa (job #2588534) | Cod sursa (job #239306)
Cod sursa(job #239306)
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
using namespace std;
#define HMAX 1<<20
#define HMSK (HMAX-1)
list<int> a[HMAX];
int N, op, x;
int find(int x)
{
int p = x&HMSK;
for (list<int> :: iterator it = a[p].begin(); it != a[p].end(); it++)
if (*it == x)
return 1;
return 0;
}
inline void add(int x)
{
if (!find(x)) a[x&HMSK].push_back(x);
}
inline void remove(int x)
{
a[x&HMSK].remove(x);
}
int main()
{
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "w", stdout);
scanf("%d", &N);
for (int i = 0; i < N; i++)
{
scanf("%d %d", &op, &x);
if (op == 1)
add(x);
else if (op == 2)
remove(x);
else
printf("%d\n", find(x));
}
return 0;
}