Pagini recente » Clasamentul arhivei educationale | Borderou de evaluare (job #1474920) | Clasamentul arhivei de probleme | Clasamentul arhivei educationale | Cod sursa (job #1988998)
#include <bits/stdc++.h>
#define MOD 666013
using namespace std;
struct tip
{
int info;
tip *next;
};
tip *HASH[MOD], *nou, *aux;
int N;
inline void add_element(tip **multime, int x)
{
for(tip *p = *multime; p != NULL; p = p -> next)
if(p -> info == x) return;
nou = (tip*)malloc(sizeof(tip));
nou -> info = x;
nou -> next = *multime;
*multime = nou;
}
inline void delete_element(tip **multime, int x)
{
if(*multime == NULL) return;
else if((*multime) -> info == x) (*multime) = (*multime) -> next;
else
{
tip *p;
for(p = *multime; p -> next -> next != NULL; p = p -> next)
if(p -> next -> info == x)
{
p -> next = p -> next -> next;
free(p -> next);
return;
}
if(p -> next -> info == x)
{
aux = p -> next;
p -> next = NULL;
free(p -> next);
}
}
}
inline void search_element(tip *multime, int x)
{
for(tip *p = multime; p != NULL; p = p -> next)
if(p -> info == x)
{
printf("1\n");
return;
}
printf("0\n");
}
void Solve(int x, int tip)
{
if(tip == 1) add_element(&HASH[x % MOD], x);
else if(tip == 2) delete_element(&HASH[x % MOD], x);
else search_element(HASH[x % MOD], x);
}
int main()
{
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "w", stdout);
int op, el;
scanf("%d", &N);
for(int i = 1; i <= N; ++i)
{
scanf("%d %d", &op, &el);
Solve(el, op);
}
return 0;
}