Pagini recente » Cod sursa (job #1882922) | Cod sursa (job #2149083) | Cod sursa (job #1301117) | Cod sursa (job #3174840) | Cod sursa (job #2596974)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("hashuri.in");
ofstream fout ("hashuri.out");
const int MOD = 649969;
int n;
class lista
{
public:
int val;
lista *next;
lista(int x)
{
next = nullptr;
val = x;
}
lista* inserare(int x)
{
lista *p = new lista(x);
p->next = this;
return p;
}
lista* stergere(lista *p, int x)
{
if(p->val == x)
{
return this->next;
}
lista* aux = p->next;
p->next = stergere(p->next, x);
if(p->next == nullptr)
delete aux;
}
bool valid(int x)
{
lista *p = this;
while(p != nullptr)
{
if(p->val == x)
return 1;
p = p->next;
}
return 0;
}
};
lista *liste[MOD];
int main()
{
fin >> n;
for(int i = 0; i < n; i++)
{
int op, x;
fin >> op >> x;
if(op == 1)
{
if(liste[x%MOD] == nullptr)
liste[x%MOD] = new lista(x);
else
liste[x%MOD] = liste[x%MOD]->inserare(x);
}
if(op == 2)
{
if(liste[x%MOD] != nullptr)
liste[x%MOD] = liste[x%MOD]->stergere(liste[x%MOD], x);
}
if(op == 3)
{
if(liste[x%MOD] == nullptr)
fout << "0\n";
else
fout << liste[x%MOD]->valid(x) << "\n";
}
}
return 0;
}