Pagini recente » Cod sursa (job #2110251) | Cod sursa (job #2956065) | Cod sursa (job #2968750) | Cod sursa (job #3038932) | Cod sursa (job #1459150)
#include <stdio.h>
#include <stdlib.h>
#define MOD 666013
#define list (x % MOD)
using namespace std;
struct node{
int key;
node *next;
} *G[MOD], *E[MOD];
inline bool find_val(int x){
node *head = G[list];
while (head){
if (head->key == x) return 1;
head = head->next;
}
return 0;
}
inline void insert_val(int x){
node *ins = new node;
ins->key = x, ins->next = NULL;
if (!G[list]){
G[list] = ins;
E[list] = G[list];
return;
}
if (!find_val(x)){
E[list]->next = ins;
E[list] = ins;
}
}
inline void erase_val(int x){
node *head = G[list];
if (!head) return;
if (head->key == x){
if (head->next) G[list] = head->next;
else G[list] = NULL;
delete head;
}
else while (head->next){
if (head->next->key == x){
node *next = head->next->next;
delete head->next;
head->next = next;
}
head = head->next;
if (!head) break;
}
}
int main()
{
int N, type, x;
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "w", stdout);
for (scanf("%d", &N); N; --N){
scanf("%d %d", &type, &x);
switch (type){
case 1:
insert_val(x);
break;
case 2:
erase_val(x);
break;
case 3:
printf("%d\n", find_val(x));
break;
}
}
return 0;
}