Pagini recente » Cod sursa (job #20820) | Cod sursa (job #34249) | Cod sursa (job #3037634) | Cod sursa (job #2890499) | Cod sursa (job #496063)
Cod sursa(job #496063)
#include <cstdio>
#include <vector>
#include <iostream>
using namespace std;
#define MOD 666667
#define pb push_back
#define IT vector<int>::iterator
vector<int>A[MOD];
inline int H(int i)
{
return i%MOD;
}
IT search(int x)
{
for (IT it = A[H(x)].begin(); it < A[H(x)].end(); ++it)
if (x == *it)
return it;
return A[H(x)].end();
}
bool exista(int x)
{
if (search(x) != A[H(x)].end())
return true;
return false;
}
void add(int x)
{
A[H(x)].pb(x);
}
void remove(int x)
{
IT it = search(x);
if (it != A[H(x)].end())
*it = 0;
}
int main()
{
FILE *f = fopen("hashuri.in", "r"), *out = fopen("hashuri.out", "w");
int n, type, x;
for(fscanf(f, "%d", &n);n; --n)
{
fscanf(f, "%d%d", &type, &x);
if (type == 1)
if (!exista(x))
add(x);
if (type == 2)
remove(x);
if (type == 3)
if (exista(x))
fprintf(out, "1\n");
else
fprintf(out, "0\n");
}
fclose(f);
fclose(out);
return 0;
}