Pagini recente » Cod sursa (job #2194558) | Cod sursa (job #1460894) | Cod sursa (job #3154698) | Cod sursa (job #2942805) | Cod sursa (job #2457240)
#include <fstream>
#define mod 666666
using namespace std;
ifstream fin ("hashuri.in");
ofstream fout ("hashuri.out");
struct nod
{
int val;
nod *urm, *prev;
};
nod *p[mod];
nod *cauta(int x)
{
int l=x%mod;
nod *q=p[l];
while(q)
{
if(q->val==x)
return q;
q=q->urm;
}
return NULL;
}
void adauga(int x)
{
int l=x%mod;
nod *q=new nod;
q->urm=NULL; q->prev=NULL; q->val=x;
if(p[l]==NULL)
{
p[l]=q;
return;
}
q->urm=p[l];
p[l]->prev=q;
}
void sterge(nod *q)
{
int l=q->val%mod;
if(q==p[l])
p[l]=p[l]->urm;
else
{
q->prev->urm=q->urm;
if(q->urm!=NULL)
q->urm->prev=q->prev;
}
delete q;
}
int n, i, t, x;
int main()
{
fin >> n;
for(i=1;i<=n;i++)
{
fin >> t >> x;
nod *q;
q=cauta(x);
if(q==NULL)
{
if(t==1)
adauga(x);
else if(t==3)
fout << "0\n";
}
else
{
if(t==2)
sterge(q);
else if(t==3)
fout << "1\n";
}
}
return 0;
}