Pagini recente » Cod sursa (job #1696299) | Cod sursa (job #2089638) | Cod sursa (job #2191889) | Cod sursa (job #235099) | Cod sursa (job #1527414)
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
ifstream ii("hashuri.in");
ofstream oo("hashuri.out");
struct nod
{
int inf; nod *urm, *last;
} *p, *gasit = NULL;
int n, i, x, op, mod;
ii >> n; nod *tab[n][2];
for (i = 0; i < n; i++)
tab[i][0] = tab[i][1] = NULL;
for (i = 0; i < n; i++, gasit = NULL)
{
ii >> op >> x; mod = x%n;
for (p = tab[mod][0]; p; p = p->urm)
if (p->inf == x)
{
gasit = p; break;
}
if (gasit)
switch (op)
{
case 1: break;
case 2:
if (gasit->last && gasit->urm)
{
gasit->last->urm = gasit->urm;
gasit->urm->last = gasit->last;
}
else if (gasit->urm)
gasit->urm->last = NULL, tab[mod][0] = gasit->urm;
else if (gasit->last)
gasit->last->urm = NULL, tab[mod][1] = gasit->last;
else
tab[mod][0] = tab[mod][1] = NULL;
delete gasit;
break;
case 3: oo << "1\n"; break;
}
else
switch (op)
{
case 1: p = new nod; p->inf = x;
if (!tab[mod][0])
{
tab[mod][0] = tab[mod][1] = p; p->last = p->urm = NULL;
}
else
{
p->urm = NULL; p->last = tab[mod][1]; tab[mod][1]->urm = p; tab[mod][1] = p;
}
break;
case 2: break;
case 3: oo << "0\n"; break;
}
}
}